見出し画像

Generative Art #126

Code

PImage img;
ArrayList<Particle> particles;

void setup() {
  size(840, 840);
  pixelDensity(2);
  colorMode(HSB, 360, 100 ,100 ,100);
  img = loadImage("profile.png");
  addP();
}

void draw() {
  for (Particle p : particles) {
    p.run();
  }
}

void addP() {
  particles = new ArrayList<Particle>();
  background(#ffffff);
  //blendMode(ADD);
  //background(0);
  for (int j = 0; j < height; j ++) {
    for (int i = 0; i < width; i ++) {
      color c = img.get(i, j);
      if (brightness(c) < 10) {
        particles.add(new Particle(i, j));
      }
    }
  }
}

void mousePressed() {
  noiseSeed((int)random(10000));
  addP();
}

void keyPressed() {
  if (key == 's')saveFrame("####.png");
}

//------------------------------------------------------

class Particle {
  PVector pos;
  float step;
  float acc;
  color col, alph;
  float angle;
  float noiseScale, noiseStrength, noiseZ;
  Particle(float x, float y) {
    pos = new PVector(x, y);
    step = 0;
    //col = color(random(120));
    col = color(random(320, 360), 90, random(50, 100));
    //col = color(random(120, 230), 70, 80);
    //col = color(random(60), 90, 80);
    alph = 8;
    noiseScale = 800;
    acc = 0.005;
    noiseStrength = 50;
    noiseZ = 0;
  }

  void show() {
    noStroke();
    fill(col, alph);
    circle(pos.x, pos.y, 1);
  }

  void move() {
    angle = noise(pos.x/noiseScale, pos.y/noiseScale, noiseZ) * noiseStrength;
    pos.x += cos(angle) * step;
    pos.y += sin(angle) * step;
    step += acc;
    noiseZ += 0.001;
  }

  void run() {
    show();
    move();
  }
}

これは美しい…パーリンノイズ様様だ!

これの構造は、こんな画像を作って

この画像の黒い部分の座標をget()で取得して、そこからパーリンノイズを使ってパーティクルを走らせた。

もっといろんな絵が描けるようになれば表現の幅が広がるぞ。

これによって僕の脳には3つくらいのやりたい表現が浮かんだので、いつか実装したい。

Happy Coding!!!

応援してくださる方!いつでもサポート受け付けてます!