xxxxxxxxxx
25
let angle = 0;
//change angleVel to see different result
//the higher the angular velocity, the shorter the period
let angleVel = 0.2;
function setup() {
createCanvas(560,390);
background(220);
stroke(63,63,147);
strokeWeight(2);
noFill();
//use beginShape() and endShape() to connect the points with a line
beginShape();
for (let x = 0; x <= width; x += 5) {
//calculate y location according to amplitude and sine of the angle
//we use map() function instead to calculate the vertical location
let y = map(sin(angle), -1, 1, 0, height);
//within beginShape(), we call vertex() to set all the vertices of our shape
vertex(x, y);
//increment the angle according to angular velocity
angle += angleVel;
}
endShape();
}