xxxxxxxxxx
40
// demonstration of the curveVertex function
// draw a sine wave on the canvas
let canvasWidth=600;
let canvasHeight=400;
let lm = 20; // left margin
let amp = 100; // amplititude of the wave from 0
let pointSpacing = 10;
let t = 0;
function setup() {
createCanvas(canvasWidth, canvasHeight);
frameRate(15); // default is 30, 15 is slower
}
function draw() {
background(245);
// draw points
noStroke(0);
fill('blue');
for (let i = 0; i < 10; i++) {
let x = i * 60 + lm;
let y = canvasHeight / 2 + sin(t + i) * amp;
circle(x, y, 10);
}
// connect points
noFill();
stroke('cyan');
strokeWeight(3);
beginShape();
for (let i = 0; i < 10; i++) {
let x = i * 60 + lm;
let y = canvasHeight / 2 + sin(t + i) * amp;
curveVertex(x, y);
}
endShape();
t += 0.1;
}