Skip to contentCREATIVE·CODE·ART
p5.js

Signal Bloom

Thousands of particles drift through a shifting flow field, leaving silk trails on charcoal. Every few seconds the field blooms — a burst of signal orange from a wandering centre. Move your mouse to stir it, click to reseed the field and trigger a bloom where you click.

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

View the code
// Signal Bloom — a generative flow-field piece in p5.js
// Palette from creativecodeart.com: charcoal #0D0D12, bone #e9e5da, signal orange #ffb454
// Move the mouse to stir the field · Click the canvas for a new bloom · Press S to save a frame
// Live sliders: Flow (turbulence) · Trails (fade) · Speed · Bloom (how often it blooms)

const BONE = [233, 229, 218];
const ORANGE = [255, 180, 84];
const BG = [13, 13, 18];

let particles = [];
let zOff = 0;
let bloomTimer = 0;
let cx, cy, cAng = 0;
let sFlow, sTrails, sSpeed, sBloom, uiBox;

function setup() {
  createCanvas(windowWidth, windowHeight);
  background(...BG);
  cx = width / 2; cy = height / 2;
  for (let i = 0; i < 2400; i++) particles.push(new Particle());
  buildControls();
}

function buildControls() {
  uiBox = createDiv();
  uiBox.style('position', 'absolute');
  uiBox.style('left', '14px');
  uiBox.style('background', 'rgba(13,13,18,0.55)');
  uiBox.style('padding', '10px 12px');
  uiBox.style('border-radius', '10px');
  uiBox.style('font-family', "'JetBrains Mono', monospace");
  uiBox.style('color', '#e9e5da');
  uiBox.style('z-index', '5');
  const row = (label, slider) => {
    const r = createDiv();
    r.parent(uiBox);
    r.style('display', 'flex');
    r.style('align-items', 'center');
    r.style('gap', '10px');
    r.style('margin', '3px 0');
    const lab = createSpan(label);
    lab.parent(r);
    lab.style('font-size', '11px');
    lab.style('width', '52px');
    lab.style('letter-spacing', '0.05em');
    slider.parent(r);
    slider.style('width', '130px');
  };
  sFlow   = createSlider(0.5, 4, 2.2, 0.1);   row('Flow', sFlow);
  sTrails = createSlider(4, 60, 16, 1);       row('Trails', sTrails);
  sSpeed  = createSlider(1, 5, 2.6, 0.1);     row('Speed', sSpeed);
  sBloom  = createSlider(120, 900, 390, 10);  row('Bloom', sBloom);
  placeControls();
}

function placeControls() {
  if (uiBox) uiBox.position(14, height - 138);
}

function draw() {
  noStroke();
  fill(BG[0], BG[1], BG[2], sTrails.value());
  rect(0, 0, width, height);
  zOff += 0.0016;
  cAng += 0.0035;
  cx = width / 2 + cos(cAng) * width * 0.14;
  cy = height / 2 + sin(cAng * 1.3) * height * 0.14;
  bloomTimer++;
  if (bloomTimer > sBloom.value()) { bloom(cx, cy); bloomTimer = 0; }
  for (const p of particles) { p.update(); p.show(); }
}

function bloom(x, y) {
  for (let i = 0; i < 240; i++) {
    const a = random(TWO_PI);
    const p = new Particle(x, y);
    p.vel = p5.Vector.fromAngle(a, random(2.5, 6.5));
    p.kind = random() < 0.75 ? 'orange' : 'bone';
    p.life = p.maxLife = random(90, 200);
    particles.push(p);
  }
  while (particles.length > 3400) particles.splice(0, particles.length - 3400);
}

function mousePressed(e) {
  if (e && e.target && e.target.tagName !== 'CANVAS') return;
  noiseSeed((Math.random() * 100000) | 0);
  bloom(mouseX, mouseY);
}

function keyPressed() {
  if (key === 's' || key === 'S') saveCanvas('signal-bloom', 'png');
}

function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
  background(...BG);
  placeControls();
}

class Particle {
  constructor(x, y) {
    this.pos = createVector(x ?? random(width), y ?? random(height));
    this.prev = this.pos.copy();
    this.vel = createVector(0, 0);
    this.maxLife = random(120, 320);
    this.life = random(this.maxLife);
    const r = random();
    this.kind = r < 0.78 ? 'bone' : (r < 0.95 ? 'orange' : 'white');
  }
  respawn() {
    this.pos = createVector(random(width), random(height));
    this.prev = this.pos.copy();
    this.vel = createVector(0, 0);
    this.life = this.maxLife = random(120, 320);
  }
  update() {
    const a = noise(this.pos.x * 0.0016, this.pos.y * 0.0016, zOff) * TWO_PI * sFlow.value();
    const force = p5.Vector.fromAngle(a, 0.35);
    const d = dist(this.pos.x, this.pos.y, mouseX, mouseY);
    if (d < 160 && mouseX !== 0) {
      const swirl = createVector(this.pos.y - mouseY, -(this.pos.x - mouseX));
      swirl.normalize().mult((1 - d / 160) * 0.55);
      force.add(swirl);
    }
    this.vel.add(force);
    this.vel.limit(sSpeed.value());
    this.prev = this.pos.copy();
    this.pos.add(this.vel);
    this.life--;
    if (this.life <= 0 || this.pos.x < -10 || this.pos.x > width + 10 ||
        this.pos.y < -10 || this.pos.y > height + 10) this.respawn();
  }
  show() {
    if (this.kind === 'orange') { stroke(ORANGE[0], ORANGE[1], ORANGE[2], 150); strokeWeight(1.6); }
    else if (this.kind === 'white') { stroke(255, 255, 255, 190); strokeWeight(1.2); }
    else { stroke(BONE[0], BONE[1], BONE[2], 95); strokeWeight(1.1); }
    line(this.prev.x, this.prev.y, this.pos.x, this.pos.y);
  }
}