رفتن به محتواCREATIVE·CODE·ART
531
22
0.5
0.6
0.31
1
0.022
0.03
3
43
100
1
p5.js

Quick experiment in psychedelic motion from 2024

Particles riding a Perlin noise flow field, leaving fading color trails. A 2024 p5.js experiment, now fully tweakable.

مجوز: CC BY-NC-SA 4.0: ریمیکس با ذکر نام، غیرتجاری، با همین مجوز

دیدن کد
let particles = [];

function setup() {
  createCanvas(windowWidth, windowHeight);
  colorMode(HSB, 360, 100, 100, 1);
  background(0);
}

function draw() {
  noStroke();
  fill(0, 0, 0, params.fade);
  rect(0, 0, width, height);

  const n = floor(params.count);
  while (particles.length < n) particles.push(new Particle());
  if (particles.length > n) particles.length = n;

  for (let particle of particles) {
    particle.update();
    particle.display();
  }
}

class Particle {
  constructor() {
    this.pos = createVector(random(width), random(height));
    this.vel = createVector(0, 0);
    this.acc = createVector(0, 0);
    this.hue = random(360);
  }

  update() {
    let angle = noise(
      this.pos.x * params.noiseScale,
      this.pos.y * params.noiseScale,
      frameCount * params.flow
    ) * TWO_PI * params.turns;
    this.acc.set(cos(angle), sin(angle));
    this.acc.mult(params.force);

    this.vel.add(this.acc);
    this.vel.limit(params.maxSpeed);
    this.pos.add(this.vel);

    if (this.pos.x < 0) this.pos.x = width;
    if (this.pos.x > width) this.pos.x = 0;
    if (this.pos.y < 0) this.pos.y = height;
    if (this.pos.y > height) this.pos.y = 0;

    this.hue = (this.hue + params.hueSpeed) % 360;
  }

  display() {
    noStroke();
    fill(this.hue, params.saturation, params.brightness, params.opacity);
    ellipse(this.pos.x, this.pos.y, params.size, params.size);
  }
}

function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
  background(0);
}