xxxxxxxxxx
36
let r = 100;
let theta = 0;
let ptheta = 0;
let x;
let y;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
//path
for (let i = 0; i < 100; i++) {
let increment = i * 2 * PI / 100
noStroke();
fill(0, 0, 0, 100);
ellipse(r * cos(theta + increment) + width / 2, r * sin(theta + increment) + height / 2, 2);
}
//velocity
let vx = - r * -1 * sin(ptheta) + width / 2;
let vy = - r * cos(ptheta) + width / 2;
stroke(255,0,0);
line(x, y, 100 * cos(ptheta) + vx, 100 * sin(ptheta) + vy);
//particle
x = r * cos(ptheta) + width / 2;
y = r * sin(ptheta) + width / 2;
ptheta -= 0.01
fill(0);
noStroke();
ellipse(x, y, 10);
}