Public
Edited
Jan 16, 2024
1 star
Insert cell
Insert cell
{
return createCanvas(W, W, draw, setup)
}
Insert cell
W = 512
Insert cell
function setup({width, height}) {

let frameCount = 0; // Set up a closure as our frame counter
const counter = () => frameCount++;
let P=PI/2048
let A,B = 0
return {P, A, B, counter}; // return object with initialized state.

}
Insert cell
// The state initialized in setup is passed as the second argument to draw.
function draw(p8g, {counter, P, A, B}){

const { background, stroke, fill, line, ellipse, text } = p8g;
const {sin, cos} = Math;

let frameCount = counter()

background(0)
for(let i=0;i<TAU+P;i+=P){
stroke(255,9)
let n=noise(i,frameCount/77)
let w=200+noise(i,frameCount)*7
line(A=w+sin(i+n)*100,B=w+cos(i+n)*100,w+sin(i+n)*W,w+cos(i+n)*W)
fill(255,3)
ellipse(A,B,n*30-15,n*30-15)
}
fill(255)
// text("F:"+frameCount,9,16)
}

Insert cell
PI = Math.PI
Insert cell
TAU = PI*2
Insert cell
Insert cell
import {noise} from "@hellonearthis/noise-like-p5js"
Insert cell
Insert cell
createCanvas = {
const p8g = await import('https://cdn.skypack.dev/p8g.js@0.8.1?min');

let canvas = null;
let _draw = () => {};
let _setup = () => {};
let request = null;
let state = null;
return async function createCanvas(width, height, draw = _draw, setup = _setup) {

// cancel previous loop
if (request) cancelAnimationFrame(request);
_setup = setup;
_draw = draw;

if (!canvas) {
canvas = await html`${p8g.createCanvas(width, height)}`;
}

state = setup(p8g);

// Draw Loop
request = requestAnimationFrame(function tick() {
draw(p8g, state);
request = requestAnimationFrame(tick);
});

invalidation.then(() => cancelAnimationFrame(request));

return canvas;
}
}
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