Cycloid c_1 = new Cycloid(0, -1.3, 132, 101, 12); Cycloid c_2 = new Cycloid(0, 1.9, 120, 87, 8); Cycloid c_3 = new Cycloid(0, 2.9, 199, -83, 6); Cycloid c_4 = new Cycloid(0, -3.7, 160, -67, 4.5); Cycloid c_5 = new Cycloid(0, 4.9, 90, 29, 3); void setup() { size(750, 750); frameRate(36); noStroke(); } public int count = 0; void draw() { background(255); c_1.update(); c_2.update(); c_3.update(); c_4.update(); c_5.update(); while (dist(c_4.xpos, c_4.ypos, c_5.xpos, c_5.ypos) <= (c_4.ballRadius + c_5.ballRadius)) { c_5.rollingRadius *= -1; break; } while (dist(c_3.xpos, c_3.ypos, c_5.xpos, c_5.ypos) <= (c_3.ballRadius + c_5.ballRadius)) { c_5.rollingRadius *= -1; break; } while (dist(c_2.xpos, c_2.ypos, c_5.xpos, c_5.ypos) <= (c_2.ballRadius + c_5.ballRadius)) { c_5.rollingRadius *= -1; break; } while (dist(c_1.xpos, c_1.ypos, c_5.xpos, c_5.ypos) <= (c_1.ballRadius + c_5.ballRadius)) { c_1.rollingRadius *= -1; break; } while (dist(c_3.xpos, c_3.ypos, c_4.xpos, c_4.ypos) <= (c_3.ballRadius + c_4.ballRadius)) { c_4.rollingRadius *= -1; break; } while (dist(c_2.xpos, c_2.ypos, c_4.xpos, c_4.ypos) <= (c_2.ballRadius + c_4.ballRadius)) { c_4.rollingRadius *= -1; break; } while (dist(c_2.xpos, c_2.ypos, c_3.xpos, c_3.ypos) <= (c_2.ballRadius + c_3.ballRadius)) { c_3.rollingRadius *= -1; break; } while (dist(c_1.xpos, c_1.ypos, c_3.xpos, c_3.ypos) <= (c_1.ballRadius + c_3.ballRadius)) { c_3.rollingRadius *= -1; break; } while (dist(c_1.xpos, c_1.ypos, c_2.xpos, c_2.ypos) <= (c_1.ballRadius + c_2.ballRadius)) { c_2.rollingRadius *= -1; break; } while (dist(c_4.xpos, c_4.ypos, c_1.xpos, c_1.ypos) <= (c_4.ballRadius + c_1.ballRadius)) { c_1.rollingRadius *= -1; break; } //count++; } class Cycloid { float xpos, ypos, angle, radspeed, staticRadius, rollingRadius, ballRadius; Cycloid(float a, float r, float sR, float rR, float bR) { //xpos = x; //ypos = y; angle = a * TWO_PI / 360; radspeed = r * TWO_PI / 360; staticRadius = sR; rollingRadius = rR; ballRadius = bR; } void update() { angle += radspeed; xpos = width / 2 + (staticRadius + rollingRadius) * cos(angle) + rollingRadius * cos(angle * (staticRadius + rollingRadius) / rollingRadius); ypos = height / 2 + (staticRadius + rollingRadius) * sin(angle) + rollingRadius * sin(angle * (staticRadius + rollingRadius) / rollingRadius); /*while (count % (rollingRadius * rollingRadius) == rollingRadius * rollingRadius - 1) { radspeed *= random(-2, 2); break; }*/ /*fill(255, 32); ellipse(width / 2 + (staticRadius + rollingRadius) * cos(angle), height / 2 + (staticRadius + rollingRadius) * sin(angle), rollingRadius * 2, rollingRadius * 2); fill(255, 16); ellipse(width / 2, height / 2, staticRadius * 2, staticRadius * 2);*/ fill(0); ellipse(xpos, ypos, ballRadius * 2, ballRadius * 2); } }