スクリーンショット_2018-08-30_16

ProcessingによるGenerative art作品#10

今流行りのgifです。Vectorの使い方も結構慣れてきました。
炎とか泡を表現したりもできそうです。

最近どうもいい作品できないなーとかモヤついていましたが、そもそも僕みたいなもんがいい作品とか何を言ってんだって話なので、うるせぇとにかく作れって結論に至りました。

Code

import java.util.*;

ArrayList<Particle> plist = new ArrayList<Particle>();

void setup() {
  size(600, 600);
  smooth();
  pixelDensity(2);
  colorMode(HSB, 360, 100, 100, 100);
}

void draw() {
  background(210, 20, 50); 
  plist.add(new Particle());
  Iterator<Particle> it = plist.iterator();

  while (it.hasNext()) {
    Particle p = it.next();
    p.run();
    if (p.isDead()) {
      it.remove();
    }
  }
}

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

class Particle {
  PVector location;
  PVector velocity;
  PVector acceleration;
  float lifespan;
  float theta;
  float rad;

  Particle() {
    theta = radians(random(360));
    rad = 200;
    location = new PVector(rad*cos(theta), rad*sin(theta));
    acceleration = new PVector(0, -0.008);
    velocity = new PVector(random(-0.5, 0.5), 0);
    lifespan = 100;
  }

  void run() {
    update();
    display();
  }

  void update() {
    velocity.add(acceleration);
    location.add(velocity);
    lifespan -= 0.6;
  }

  void display() {
    float w = map(lifespan, 100, 0, 50, 1);
    pushMatrix();
    translate(width/2, height/2);
    for (int i=0; i<10; i++) {
      float r = map(i, 0, 10, w, 0);
      noStroke();
      fill(13, 90, 80, 10);
      ellipse(location.x, location.y, r, r);
    }
    popMatrix();
  }

  boolean isDead() {
    if (lifespan<0.0) {
      return true;
    } else {
      return false;
    }
  }
}

Happy coding!

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