Published
Edited
Feb 18, 2022
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
if (window.p_inst !== undefined) {
window.p_inst.remove();
}

window.p_inst = new P5(
(p) => {
p.setup = setup(p);
p.draw = draw(p);
},
document.querySelector("#view"),
true
);

return "Succeed";
}
Insert cell
function setup(p) {
return () => {
p.createCanvas(640, 640); // updatePixels not work in WEBGL mode
p.pixelDensity(1);
};
}
Insert cell
function draw(p) {
let count = 127;

return () => {
count += 1;
if (count == 255) {
count = 127;
}

mutable Output = p.frameCount;

p.background(255);
p.loadPixels();

for (var y = 0; y < p.height; y++) {
for (var x = 0; x < p.width; x++) {
var index = (x + y * p.width) * 4;
//if (x % 16 == 0 && y % 8 == 0) {
if (x < y && x % 16 != 0) {
p.pixels[index + 0] = (2 * x) % count;
p.pixels[index + 1] = (3 * y) % count;
p.pixels[index + 2] = 2 * count;
} else {
p.pixels[index + 0] = 127 % count; // red
p.pixels[index + 1] = 0;
p.pixels[index + 2] = 0;
}
p.pixels[index + 3] = 255; // alpha
}
}

p.updatePixels();
};
}
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more