Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

パーティクルの花

/**
* flower of particles
*
* @author aa_debdeb
* @date 2016/09/18
*/

ArrayList<Particle> particles;

void setup(){
  size(640, 640);
  colorMode(HSB, 360, 100, 100);
  particles = new ArrayList<Particle>();
  for(int i = 0; i < 50; i++){
    particles.add(new Particle());
  }
  background(0, 0, 100);
}

void draw(){
  translate(width / 2, height / 2);
  for(Particle p: particles){
    p.update();
  }
}

class Particle{
  
  float t;
  float aSpeed;
  color c;
  
  Particle(){
    t = random(1000);
    c = color(320, random(0, 60), 100, 100);
    aSpeed = random(PI / 256, PI / 128);
  }
  
  void update(){
    float nt = t + 1;
    float r = map(sin(t * 0.1), -1, 1, 0, 200);
    float nr = map(sin(nt * 0.1), -1, 1, 0, 200);
    float a = t * aSpeed;;
    float na = nt * aSpeed;;
    float x1 = r * sin(a);
    float y1 = r * cos(a);
    float x2 = nr * sin(na);
    float y2 = nr * cos(na);
    stroke(c);
    line(x1, y1, x2, y2);
    t = nt;
  }
  
}
f:id:aa_debdeb:20160916182320j:plain