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

ProcessingでGenerative art#11

面白い形になりましたね。
小さい渦が大きな渦を生み出しています。フラクタってますね!

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() {
  noStroke();
  fill(0,5);
  rect(0, 0, width, height);
  
  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;
  float angle;
  Particle() {
    theta = radians(random(360));
    rad = 250;
    location = new PVector(rad*cos(theta), rad*sin(theta));
    acceleration = new PVector();
    velocity = new PVector();

    lifespan = 100;
  }

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

  void update() {
    PVector center = new PVector(0, 0);
    PVector dir = PVector.sub(center, location);
    dir.normalize();
    dir.mult(0.01);
    acceleration = dir;

    velocity.add(acceleration);
    location.add(velocity);
    lifespan -= 0.4;
    angle += 0.05;

    acceleration.mult(0);
  }

  void display() {
    float w = 10 * sin(map(lifespan, 100, 0, 0, PI));
    pushMatrix();
    translate(width/2, height/2);
    pushMatrix();
    translate(location.x, location.y);
    rotate(angle);
    noStroke();
    noFill();
    fill(150, 50, 80, 20);
    ellipse(50, 0, w, w);
    popMatrix();
    popMatrix();
  }

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

Happy coding!

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