Published
Edited
Oct 12, 2021
Fork of Pixel
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable image = ""
Insert cell
Insert cell
{
if (window.p_inst !== undefined) {
window.p_inst.remove();
}

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

return "Succeed";
}
Insert cell
function preload(p) {
return async () => {
mutable image = p.loadImage(await FileAttachment("sample.png").url());
};
}
Insert cell
function setup(p) {
return () => {
p.createCanvas(960, 640); // updatePixels not work in WEBGL mode
};
}
Insert cell
function draw(p) {
return () => {
p.image(mutable image, 0, 0);

const c = mutable image.get(p.mouseX, p.mouseY);
p.fill(c);
p.circle(p.mouseX, p.mouseY, 60);

mutable Output = c;
};
}
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