Skip to contentCREATIVE·CODE·ART
1
80
9
1
265
p5.js

Slider Meadow

A meadow built to be played with. Every slider under this work changes something you can really see — start with Wind, then Bloom. The live example for the sliders guide.

Licence: CC BY-NC-SA 4.0: remix with credit, non-commercial, share alike

View the code
function setup() {
  createCanvas(600, 600);
  colorMode(HSB, 360, 100, 100, 100);
}
function draw() {
  background(params.hue, 45, 16);
  const t = frameCount * 0.02 * params.speed;
  const n = int(params.bloom);
  noStroke();
  fill(params.hue, 40, 24);
  beginShape();
  vertex(0, 600);
  for (let x = 0; x <= 600; x += 20) {
    vertex(x, 400 + 26 * sin(x * 0.008 + t * 0.4));
  }
  vertex(600, 600);
  endShape(CLOSE);
  fill((params.hue + 40) % 360, 45, 20);
  rect(0, 452, 600, 148);
  for (let i = 0; i < n; i++) {
    const fx = (i * 197.3) % 600;
    const fy = 470 + ((i * 89.7) % 118);
    const sway = sin(t + i * 1.7) * params.wind * 9;
    const h = 26 + (i % 5) * 7;
    stroke((params.hue + 60) % 360, 55, 42);
    strokeWeight(2);
    noFill();
    bezier(fx, fy, fx, fy - h * 0.5, fx + sway, fy - h * 0.6, fx + sway, fy - h);
    noStroke();
    const cx = fx + sway;
    const cy = fy - h;
    const ps = params.size * (0.7 + (i % 4) * 0.22);
    fill((params.hue + i * 23) % 360, 70, 95);
    for (let p = 0; p < 5; p++) {
      const a = (p / 5) * TWO_PI + t * 0.3;
      circle(cx + cos(a) * ps * 0.62, cy + sin(a) * ps * 0.62, ps * 0.85);
    }
    fill(48, 90, 100);
    circle(cx, cy, ps * 0.55);
  }
}