//define the sketch as an empty object let sketch1 = {} let sketch2 = {} let sketch3 = {} //these loops are then called from within p5's //setup and draw loops function setup() { createCanvas(windowWidth,windowHeight) defineSketches() sketch1.setup() } function draw() { sketch1.draw() } const defineSketches = () => { sketch1.setup = () => {} sketch1.draw = () => { background(242) noFill() for (let i = 0; i < 360; i += 3) { let x = cos(radians(i)) * 50 + width / 2; let y = sin(radians(i)) * 100 + height / 2; let w = sin(radians(frameCount + i)) * 200; w = abs(w); let col = map(i, 0, 360, 120, 255); fill(col, col, col); noStroke(); fill(col, 0, 88); ellipse(x, y, w, w); } } sketch2.setup = () => {} sketch2.draw = () => { background(255, 0, 88); let w = width / 270; stroke(200, 200); strokeWeight(3) for (let i = 0; i < width; i += 8) { let l = 75 * sin(radians(i - frameCount)); let r = 12 * sin(radians(i + frameCount)); let p = 4 * sin(PI / 4 + radians(i - frameCount)); stroke(242); strokeWeight(1) line(i * w, 0, i * w, height / 2 + l); line(i * w + 5, height, i * w + 5, height / 2 - l); noStroke() fill(242) ellipse(i * w, height / 2 + l, r, r); ellipse(i * w + 5, height / 2 - l, p, p); } } sketch3.setup = () => { smooth(); noStroke(); fill(255); n = 600; //number of ellipse per circle m = 10; //magnitude of waves f1 = 2000; //f general f2 = 2; //f of rotation f3 = 5; //f of waves } sketch3.paintCircle = (t, o) => { for (let i = 0; i < n; i++) { let p = (i / n) * TWO_PI; let x = (width / 2) + sin(p + t) * (200 + sin((t * f2 + p) * f3 + o) * m * (1 - sin(p))); let y = (height / 2) + cos(p + t) * (200 + sin((t * f2 + p) * f3 + o) * m * (1 - sin(p))); ellipse(x, y, 5, 5); } } sketch3.draw = () => { background(242); let t = millis() / f1; fill(255, 0, 88, 150) sketch3.paintCircle(t, 0); fill(127, 0, 88, 150) sketch3.paintCircle(t, PI); } }