Public
Edited
Oct 18, 2022
1 star
Insert cell
Insert cell
Insert cell
// Changing canvas size means you have to reload page
createCanvas(w, w)
Insert cell
w = 512
Insert cell
// The helper functions further below let you define a
// draw function as a regular cell, just like you would
// with Processing or P5js. It is called once per frame.
function draw(){

const {
background,
stroke,
point,
} = p8g;

const {sin, PI} = Math;

background(0);
for(let y=1;y<=(w-1);y++) {
for(let x=1;x<=(w-1);x++){
stroke(255*noise(y,0),alpha); // added alpha
point(99*noise((x-y)/99+window.r,window.r)*sin((x+y)/99)+y,x);
}
}
window.r-=PI/99;
}
Insert cell
window.r = 0
Insert cell
import {noise} from "@hellonearthis/noise-like-p5js"
Insert cell
Insert cell
Insert cell
async function createCanvas(width, height) {
return html`${p8g.createCanvas(width, height)}`;
}
Insert cell
// The normal p8g approach would be to assign a draw function to
// the p8g object, but because it's imported through skypack
// at runtime the p8g module is read-only. So instead we use
// this workaround. As a bonus, we can write the draw() function
// as a named cell.
p8g_readonly_workaround = {
await p8g;
// Draw Loop
let request = requestAnimationFrame(function tick() {
draw();
request = requestAnimationFrame(tick);
});

invalidation.then(() => cancelAnimationFrame(request));
}
Insert cell
p8g = await import('https://cdn.skypack.dev/p8g.js@0.8.1?min');
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