xxxxxxxxxx
27
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
let angle = 0;
let angleVelocity = 0.2;
let amplitude = 100;
function setup() {
createCanvas(640, 240);
}
function draw() {
background(255);
stroke(0);
strokeWeight(2);
fill(127, 127);
for (let x = 0; x <= width; x += 24) {
// 1) Calculate the y position according to amplitude and sine of the angle.
let y = amplitude * sin(angle);
// 2) Draw a circle at the (x,y) position.
circle(x, y + height / 2, 48);
// 3) Increment the angle according to angular velocity.
angle += angleVelocity;
}
}