xxxxxxxxxx
void setup() {
size (800, 600);
noFill();
}
void drawDiameters(int count, float phase) {
pushMatrix();
pushStyle();
int reddish = color(204, 51, 0);
int greenish = color(102, 153, 51);
int blueish = color(51, 102, 153);
strokeWeight(2);
translate(width / 2, height / 2);
float radius = min(height * 3 / 8f, width * 3 / 8f);
float sliceAngle = PI/count;
for (int i = 0; i < count; i++) {
rotate(sliceAngle);
float relativeSliceIndex = map(i, 0, count, 0, 1f);
int myColour = lerpColor(reddish, greenish, relativeSliceIndex);
stroke(myColour);
line (-radius, 0, radius, 0);
float angularOffset = i * sliceAngle;
float angularPhase = 2 * PI * phase;
float parameter = sin(angularPhase + angularOffset);
pushStyle();
stroke (blueish);
strokeWeight(20);
point (parameter*radius, 0);
popStyle();
}
stroke(255);
ellipse(0, 0, radius*2, radius*2);
popMatrix();
popStyle();
}
void draw() {
background(32);
int count = (int) map(mouseX, 0, width, 1, 10);
float cycleDuration = 60f * 5;
float phase = frameCount / cycleDuration;
drawDiameters(count, phase);
}