Published
Edited
Oct 30, 2019
Insert cell
Insert cell
{
let ctx = DOM.canvas(width, height).getContext("2d");
let coords = wave()
for (let i = 0; i < width; i++) {
let [x, y] = coords[i]
ctx.fillRect(x, y + (height- 1)/2, 1, 1);
}
return ctx.canvas
}
Insert cell
function wave() {
let a = (height - 1) / 2;
let f = (2 * Math.PI) / width;
let p = 0;
let w = width;
let coords = [];
for (let t = 0; t < w; t++) {
let y = a * Math.sin(f * t+ p)
coords.push([t,y])
}
return coords
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more