/* * Animation of the creation of a star mandala. * * Animated sketch by Michael Goldwasser, based on static sketch from * text book by Greenberg, Xu, and Kumar. */ int steps = 300; int pointCount = 8; float innerRadiusFactor = 0.7; float totalRotation = 55.0; float outerRadius; float innerRadius; float outerRadiusRatio; float innerRadiusRatio; float shadeRatio; float rotationRatio; String display; void setup() { size(600, 600); noStroke(); textAlign(CENTER, TOP); translate(width/2, height/2); outerRadius = 0.475 * width; reset(); frameRate(60); } String makeString() { return ("Points: " + pointCount + "; rotation: " + nf(totalRotation, 3, 2) + " degrees; " + " inner factor: " + nf(innerRadiusFactor, 0, 3)); } void reset() { // values derived from above parameters innerRadius = outerRadius * innerRadiusFactor; outerRadiusRatio = outerRadius/steps; innerRadiusRatio = innerRadius/steps; shadeRatio = 255.0/steps; rotationRatio = totalRotation/steps; display = makeString(); background(0); fill(255); text(display, 0, -0.5*height); } void draw() { translate(width/2, height/2); if (frameCount % steps == 0) { waitasec(2); pointCount = int(random(3, 12)); innerRadiusFactor = random(0.2, 0.9); totalRotation = random(10.0, 180.0); reset(); } int i = frameCount % steps; fill(shadeRatio*i); pushMatrix(); rotate(rotationRatio*i*PI/180); star(pointCount, outerRadius-outerRadiusRatio*i, innerRadius-innerRadiusRatio*i); popMatrix(); } void waitasec(int sec) { int start = millis(); int end = start + 1000*sec; while (millis() < end) { }; } void star(int pointCount, float innerRadius, float outerRadius) { float theta = 0.0; // point count is 1/2 of total vertex count int vertCount = pointCount*2; float thetaRot = TWO_PI/vertCount; float tempRadius = 0.0; float x = 0.0, y = 0.0; beginShape(); for (int i=0; i