Published
Edited
Sep 12, 2019
2 stars
Insert cell
Insert cell
Insert cell
p5(sketch => {
let y_off = 0;
let x_off = 0;
let yoff = 0.01;
let xoff = 0.01;
sketch.setup = function() {
sketch.createCanvas(width / 2, height);
};
sketch.draw = function() {
y_off = y_off >= resolution + sketch.height * 2 ? 0 : y_off + 1;
x_off = x_off >= resolution + sketch.width * 2 ? 0 : x_off + 1;

const ypulse = pulse_shift(y_off, sketch.height * 2);
const xpulse = pulse_shift(x_off, sketch.width * 2);
sketch.loadPixels();
var buf = new ArrayBuffer(sketch.pixels.length);
var buf8 = new Uint8ClampedArray(buf);
var data = new Uint32Array(buf);
for (let y = 0; y < sketch.height * 2; y++, yoff += 0.01) {
for (let x = 0; x < sketch.width * 2; x++, xoff += 0.01) {
const index = (x + y * sketch.width * 2) * 4;
// const [r, g, b] = parse_color(ypulse[y] + xpulse[x]);
const grey = (ypulse[y] + xpulse[x]) * 255;
data[y * sketch.width * 2 + x] =
(255 << 24) | // alpha
(grey << 16) | // blue
(grey << 8) | // green
grey; // red
// sketch.pixels[index] = grey;
// sketch.pixels[index + 1] = grey;
// sketch.pixels[index + 2] = grey;
// sketch.pixels[index + 3] = 0xff;
}
}
sketch.pixels.set(buf8);
sketch.updatePixels();
};
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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