import java.lang.Math; float HUE_RANGE = 360; float ALPHA_RANGE = 100; int TRIANGLE_COUNT = 5; int FRAME_PER_SEC = 24; int VERTEX_COUNT = 3; float degNoise = random(10); float radNoise = random(10); int degree = 45; int baseRadius = height; void setup() { size(480, 480); colorMode(HSB, HUE_RANGE, 100, 100, ALPHA_RANGE); smooth(); frameRate(FRAME_PER_SEC); background(HUE_RANGE - 1); strokeWeight(1); } PVector[] createVertex( int centerX, int centerY, int radius, int startDegree) { PVector vectors[] = new PVector[VERTEX_COUNT]; int index = 0; for (int degree = startDegree; degree < 360 + startDegree; degree += (360 / VERTEX_COUNT)) { float rad = radians(degree); vectors[index++] = new PVector(centerX + (radius * cos(rad)), centerY + (radius * sin(rad))); } return vectors; } void drawPolygonSide( PVector fromPoint, PVector toPoint, float colorAlpha) { PVector v = new PVector(toPoint.x - fromPoint.x, toPoint.y - fromPoint.y); float a = degrees((float)Math.atan2(v.y, v.x)); v.mult(2); float vlen = v.mag(); float lastX = fromPoint.x + v.x; float lastY = fromPoint.y + v.y; float step = 0.33; for (float degree = step; degree < 9; degree += step) { vlen *= 0.985; float c = (HUE_RANGE * 3 / 4) + ((HUE_RANGE - (HUE_RANGE * 3 / 4)) * (degree / 9)); float rad = radians(a - degree); float x = (vlen * cos(rad)); float y = (vlen * sin(rad)); stroke(c, colorAlpha); fill(c, colorAlpha); beginShape(); vertex(fromPoint.x, fromPoint.y); vertex(lastX, lastY); vertex(fromPoint.x + x, fromPoint.y + y); endShape(CLOSE); lastX = fromPoint.x + x; lastY = fromPoint.y + y; } stroke(HUE_RANGE / 2, colorAlpha); line(fromPoint.x, fromPoint.y, fromPoint.x + v.x, fromPoint.y + v.y); } void drawPolygon( int centerX, int centerY, int radius, int startDegree, float alphaRatio) { float colorAlpha = (ALPHA_RANGE / 10 * alphaRatio); PVector vectors[] = createVertex(centerX, centerY, radius, startDegree); for (int index = 0; index < VERTEX_COUNT; index++) { drawPolygonSide(vectors[index], vectors[VERTEX_COUNT <= index + 1 ? 0 : index + 1], colorAlpha); } } void draw() { int updateFrameCount = FRAME_PER_SEC; int frameNo = (frameCount - 1) % updateFrameCount; if (frameNo == 0) { degree = (int)(noise(degNoise) * 360); baseRadius = (int)(height + height * noise(radNoise)); degNoise += 0.1; radNoise += 0.5; } int centerX = width / 2; int centerY = height / 2; float ar = frameNo / (float)updateFrameCount; for (int index = TRIANGLE_COUNT; 1 <= index; --index) { drawPolygon(centerX, centerY, baseRadius / (TRIANGLE_COUNT * index), degree * index % 360, ar); } } void keyPressed() { if (keyCode == ' ') { background(random(HUE_RANGE)); } }