let g = 9.81;
let a,c;
let cMode = 0;
setup = () => {
c = min(windowWidth, windowHeight) * 0.9;//clearly a variable
createCanvas(windowWidth, windowHeight);
a = -c / 3;
stroke(255 - cMode);
strokeWeight(0.5);
noFill();
};
draw = () => {
background(cMode);
stroke(255 - cMode);
t = frameCount / 7;
translate(width / 2, height / 2);
strokeWeight(2);
for (let i = 0.7; i < 40; i += 0.5) {
push();
scale(1 / i, 1 / i);
circle(0, -c / 4, 5);
pendulum(2 * i);
pop();
}
strokeWeight(0.15);
vanish(a + (c / 8) * sin(t / 100), 0);
vanish(-a - (c / 8) * sin(t / 100), 0);
};
pendulum = (f) => {
L = c / 2 - min(c / 2, f);
T = TWO_PI * sqrt(L / g);
theta0 = PI / 2.75;
A = theta0 * cos(sqrt(g / L) * t);
x = L * sin(A);
y = L * cos(A);
line(0, -c / 4, x, -c / 4 + y);
circle(x, -c / 4 + y, 5);
};
vanish = (a, b) => {
circle(a, b, 3);
n = 45
for (let i = 0; i < n; i++) {
push();
translate(a, b);
rotate((PI / n) * i);
line(-c, 0, c, 0);
pop();
}
};
windowResized = () => {
c = min(windowWidth, windowHeight) * 0.9;
resizeCanvas(windowWidth, windowHeight);
};
mousePressed = () => {
if (cMode === 0) {
cMode = 255;
} else {
cMode = 0;
}
};