xxxxxxxxxx
27
// Sin Cos wave
//
// Adapted from Processing textbook
//
function setup() {
createCanvas(400, 100);
background(220);
// Draws a wave across the screen (setup omitted, canvas is 700 x 70)
noStroke();
let angle = 0;
for (let x = 0; x <= width; x += 5) {
fill(0);
let y = 50 + (sin(angle) * 35);
rect(x, y, 2, 4);
fill(255);
y = 50 + (cos(angle) * 35);
rect(x, y, 2, 4);
angle += PI / 15;
}
}