-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vein.java
77 lines (63 loc) · 2.08 KB
/
Vein.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import processing.core.PApplet;
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Queue;
import org.apache.commons.io.FileUtils;
public class Vein extends PApplet {
Queue<TransientRandomWalker> veins = new ArrayDeque<>();
float incSize = 0.0001f;
float maxSteps = 1000;
float steps = 0;
float divisionProbability = 0.005f;
public void settings() {size(900,900);}
public void setup() {
steps = maxSteps;
background(255);
fill(0);
for (int i = 0; i < 10; i++) {
float x = random(0, width);
float y = random(0, height);
veins.add(new TransientRandomWalker(this, x, y, 10, 1000, incSize));
}
File file = new File("output");
try {
FileUtils.cleanDirectory(file);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void draw() {
if (steps > 0) {
float alpha = map(steps, maxSteps, 0, 0, 10);
System.out.println(alpha);
fill(0, alpha);
stroke(0, alpha);
int veins_remaining = veins.size();
while (veins_remaining > 0) {
TransientRandomWalker vein = veins.poll();
vein.step2();
if (random(0,1) < divisionProbability) {
TransientRandomWalker newVein = new TransientRandomWalker(
this, vein.x, vein.y, vein.size, vein.steps, incSize
);
veins.add(newVein);
}
if (vein.steps > 0) {
veins.add(vein);
}
veins_remaining -= 1;
}
// saveFrame("output/frame-########.png");
steps--;
} else {
saveFrame("output/frame-########.png");
exit();
}
}
public static void main(String[] args) {
String[] processingArgs = {"MySketch"};
Vein mySketch = new Vein();
PApplet.runSketch(processingArgs, mySketch);
}
}