p5(sketch => {
sketch.setup = () => {
sketch.createCanvas(width, 400);
};
let angle = 0;
let barWidth = 40;
let barPadding = 2;
let barHeight = 120;
const angleScale = d3.scaleLinear()
.domain([-1, 1])
.range([0, barHeight]);
sketch.draw = () => {
sketch.background(0);
sketch.translate(sketch.width / 2, sketch.height / 2);
sketch.rectMode(sketch.CENTER);
sketch.fill(255);
let offset = 0;
for (let x = 0; x < sketch.width; x += barWidth) {
let a = angle + offset;
let h = angleScale(sketch.sin(a));
sketch.rect(x - sketch.width / 2 + barWidth / 2, 0, barWidth - 2, h);
offset += angleOffset;
}
angle += 0.1;
}
})