float startTime = 0.0;
float drawTime = 0.0;
PVector lastPoint;
PGraphics pg;
void setup() {
size(600, 600);
background(245);
reset();
}
void reset() {
startTime = millis();
drawTime = 0.0;
pg = createGraphics(width, height);
}
/*
We are going to roll one ball around another of twice the size.
The point on the perimeter of the outer ball traces out a curve called a ...
*/
void draw() {
float r0 = 100;
float r1 = 100;
int n = round((r0 + r1) / r1);
float t = (millis() - startTime) * 0.001;
float dt = t - drawTime;
background(245);
//This is the inner ball
PVector center = new PVector(0.5 * width, 0.5 * height);
fill(255);
ellipse(center.x, center.y, 2 * r0, 2 * r0);
PVector orbit = new PVector(cos(2.0 * t), sin(2.0 * t)).mult(r0);
PVector origin = PVector.add(center, new PVector(cos(5.0 * t), sin(5.0 * t)).mult(r0));
PVector p1 = PVector.add(center, orbit);
float r = PVector.sub(p1, origin).mag();
noFill();
ellipse(p1.x, p1.y, 2 * r, 2 * r);
line(origin.x, origin.y, p1.x, p1.y);
ellipse(p1.x, p1.y, 5, 5);
ellipse(origin.x, origin.y, 5, 5);
if (dt > TWO_PI / 300) {
pg.noFill();
pg.strokeWeight(1);
pg.stroke(0, 30);
pg.ellipse(p1.x, p1.y, 2 * r, 2 * r);
drawTime = t;
}
image(pg, 0, 0, width, height);
}