We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have this sketch:
let h = 0;
let k = 0;
let step = 0.05;
let r = 200;
let points = [];
let i = 0;
let forward = true;
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(81);
translate(width / 2, height / 2);
noFill();
strokeWeight(1);
stroke(255);
beginShape();
for (let theta = TWO_PI; theta > PI; theta -= step) {
let x = h + r * Math.cos(theta);
let y = k - r * Math.sin(theta);
vertex(x, y);
points.push(createVector(x, y));
}
endShape();
strokeWeight(10);
stroke(0);
point(points[i].x, points[i].y);
}
That shows a dot moving from one side of an arc to another. When it gets to the end, however it teleports back to the start. I want to make it swing back and forth on the arc. I have tried it using the length of the points array, but that seems to be massively overflowed and it contains duplicate points. Is there a way to do this, or a better way to do what I have done?
Answers
This is much easier:
That runs very slow. Is there a way to make this run smoother?
For smoother, I suppose you can change the value of step. I the following example I am using draw to update the position. I draw the arc in a second graphics buffer in setup and draw in in draw().
Kf