xxxxxxxxxx
Root[] roots = new Root[0];
void setup() {
size(screen.width, screen.height);
background(0);
stroke(241, 30, 3, 15);
smooth();
}
void draw() {
for (int i = 0; i < roots.length; i++) {
if (!roots[i].finished())
roots[i].drawLines();
}
if (mousePressed) {
roots = (Root[]) append(roots, new Root(mouseX, mouseY, 8, random(100), 1));
}
}
void mousePressed() {
background(0);
for (int i = 0; i < roots.length; i++) {
roots[i].tm = 1;
}
}
class Root {
float X;
float Y;
float rot;
float V;
float tm;
int fm;
Root(int tX, int tY, float tfm, float trot, float tV) {
X = tX;
Y = tY;
rot = trot;
tm = tfm;
V = tV;
}
void drawLines() {
V += random(-0.03, 0.03);
tm /= 1.01;
strokeWeight(tm);
rot += random(-0.2, 0.2);
line(X, Y, X + V*sin(rot), Y + V*cos(rot));
line(X, Y, X + V*sin(rot), Y + V*cos(rot));
X += V*sin(rot);
Y += V*cos(rot);
fm++;
if (random(400) > 398.5-(fm/20)) {
roots = (Root[]) append(roots, new Root(int(X), int(Y), tm, rot + random(-0.2, 0.2), V));
}
}
boolean finished() {
if (tm < 1.01) {
return true;
} else {
return false;
}
}
}