ProcessingでGenerative art #43
Code
import java.util.*;
ArrayList<Particle> particles;
void setup() {
size(800,600);
pixelDensity(2);
smooth();
colorMode(HSB, 360, 100, 100, 100);
background(360);
particles = new ArrayList<Particle>();
}
void draw() {
if(mousePressed){
particles.add(new Particle(new PVector(mouseX, mouseY)));
}
Iterator<Particle> it = particles.iterator();
while(it.hasNext()){
Particle p = it.next();
p.run();
if(p.isDead()){
it.remove();
}
}
}
//---------------------------------------------------
class Particle {
PVector pos;
PVector vel;
PVector acc;
float lifespan;
float angle, angleStep;
float d, r;
float s, b;
Particle(PVector l) {
acc = new PVector(random(-0.05, 0.05), random(-0.05, 0.05));
vel = new PVector(0, 0);
pos= l.get();
lifespan = 100.0;
angle = random(PI*2);
r = random(50);
d = random(5, 30);
s = random(100);
b = random(50, 100);
angleStep = random(0.1);
}
void run() {
update();
display();
}
void update() {
vel.add(acc);
pos.add(vel);
lifespan -= 1.5;
angle += angleStep;
}
void display() {
noStroke();
fill(340, s, b, lifespan);
pushMatrix();
translate(pos.x, pos.y);
rotate(angle);
ellipse(0, r, map(lifespan, 100, 0, 0, d), map(lifespan, 100, 0, 0, d));
popMatrix();
}
boolean isDead() {
if (lifespan < 0.0) {
return true;
} else {
return false;
}
}
}
応援してくださる方!いつでもサポート受け付けてます!