Home > Blockchain >  Smooth rotation with second
Smooth rotation with second

Time:12-19

I was wondering if there is any way to make a smoother rotation of the circle?

This is what I have so far:

  let angle = 0;
  let pointCount = 12;
  let speed;
  strokeWeight(60);

  rotate(second());
  for(let i = angle; i < radians(360   angle) ; i  = radians(360 / pointCount)){
    let x = width / 2 * Math.cos(i);
    let y = width / 2 * Math.sin(i);
    point(x, y)
  }

The rotation jumps every second, but I would like it to move smoothly.

I used rotate because I think it would be the most simple way, but if it's inconvenient please let me know if I should try something else.

CodePudding user response:

Use the millis() function:

Returns the number of milliseconds (thousandths of a second) since starting the sketch [...]

The default unit of the rotate() angel is radians. If you want a complete ture every second, you have to scale the number of milliseconds by 2*PI / 1000:

rotate(millis() * 2*PI / 1000);
  • Related