Public
Edited
Oct 18, 2022
1 star
Insert cell
Insert cell
Insert cell
{
return createCanvas(W, W, draw, setup)
}
Insert cell
W = 720
Insert cell
function setup({width, height}) {

let frameCount = 0; // Set up a closure as our frame counter
const counter = () => frameCount++;
let t = 0
const incT = () => t+=0.1;

let X,Y,R = 0

return {incT, X, Y, R}; // return object with initialized state.

}
Insert cell
// The state initialized in setup is passed as the second argument to draw.
function draw(p8g, {incT, X, Y, R}){

const { background, stroke, colorMode, HSB, line, translate, fill} = p8g;
const {sin, cos} = Math;

background(0)
let t = incT()
colorMode(HSB)
// B=blendMode
// B(BLEND)
background(1,1,1,0.5)
// B(ADD)
p8g.strokeWeight(3)
translate(W/2,W/2)
for(let r=0;r<TAU+(X=Y=0);r+=0.1){
for(let d=0;d<slider;d++){
stroke(r*53,W,d,0.5)
line(X,Y,X+=cos(R=r+(noise(sin(r*6),d/40-t)-.5)*d/6)*4,Y+=sin(R)*4)
}
}
}
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