This repository has been archived by the owner on Oct 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.pde
142 lines (134 loc) · 3.16 KB
/
particle.pde
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class Particle {
PVector pos;
PVector desiredPos;
char currentChar;
int stability = particleStability;
int vitality = particleVitality;
int tailLength = particleTailLength;
int age = 0;
float speed = 1;
boolean humanReadable = false;
int charIndex = 0; // used to display characters in order if humanReadable
Particle tail;
Particle() {
desiredPos = randomPos();
pos = desiredPos.copy();
speed = random(minSpeed, maxSpeed);
newChar();
}
Particle copy() {
Particle p = new Particle();
p.pos.x = pos.x;
p.pos.y = pos.y;
p.desiredPos.x = desiredPos.x;
p.desiredPos.y = desiredPos.y;
p.currentChar = currentChar;
p.stability = stability;
p.vitality = vitality;
p.age = age;
p.humanReadable = humanReadable;
p.tailLength = tailLength;
if (tail != null) {
p.tail = tail.copy();
}
return p;
}
void newChar() {
if (humanReadable) {
newChar(humanReadableChars[charIndex%humanReadableChars.length]);
charIndex++;
} else {
newChar(chars[int(random(chars.length))]);
}
}
void newChar(char c) {
currentChar = c;
}
void tick() {
if (age == 0) {
desiredPos.y += lineHeight*speed;
}
if (desiredPos.y - pos.y >= lineHeight) {
while(desiredPos.y - pos.y >= lineHeight) {
move();
//draw();
}
} else {
//draw();
}
draw();
if (tail != null) {
tail.draw();
}
}
void draw() {
if (tail != null) {
if (tail.age >= tailLength) {
tail = null;
} else {
//tail.draw();
}
}
if (age == 0) {
fill(200, 255, 200);
} else {
if (tail != null) {
tail.draw();
}
fill(0, 255, 0, map(age, 0, tailLength, 255, 0));
age++;
}
pushMatrix();
translate(pos.x+0.5*colWidth, pos.y);
if (humanReadable) {
textFont(humanReadableFont, int(lineHeight*1.3));
//translate(pos.x+0.5*colWidth, pos.y);
rotate(HALF_PI);
}
text(currentChar,0,0);
popMatrix();
if (humanReadable) {
textFont(font, int(lineHeight*1.85));
} else if (int(random(stability))==0 && stability > 0) {
newChar();
}
}
void move() {
tail = this.copy();
tail.age ++;
tail.stability /= 2;
if (humanReadable) {
pos.y += lineHeight*0.6;
} else {
pos.y += lineHeight;
}
if (pos.y >= height) {
pos.y = desiredPos.y = 0;
if (humanReadable) {
pos.x = desiredPos.x = pos.x+colWidth;
if (pos.x > width-xMax) {
desiredPos = randomPos();
pos = desiredPos.copy();
}
}
}
if (int(random(vitality))==0 && vitality > 0) {
desiredPos = randomPos();
pos = desiredPos.copy();
speed = random(minSpeed, maxSpeed);
newChar();
}
if (humanReadable) {
newChar();
}
}
PVector randomPos() {
return new PVector(int(random(int((width-xOffset-xMax)/colWidth)))*colWidth+xOffset, int(random(int(height/lineHeight)))*lineHeight);
}
void makeHumanReadable() {
humanReadable = true;
vitality = 200;
speed = 0.3;
tailLength = humanReadableChars.length*4;
}
}