-
Notifications
You must be signed in to change notification settings - Fork 0
/
csanim.pde
138 lines (125 loc) · 3.27 KB
/
csanim.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
String[] rawTexts= {
"All your base are belong to us.",
"For great Justice !",
"You set up us the bomb",
"code story FTW",
"I can digest more slides",
"Show me some code",
"Am I in the Matrix ?",
"You don't write test, you die",
"You aren't going to need it",
"Live Coding is just plain HARD",
"Enjoy DEVOXX",
"Jean-Laurent",
"David",
"Eric",
"Sebasti[a|e]n",
"JigSaw will never be out",
"Scala will die",
"CoffeeScript is missing some ;",
"You just don't need c#",
"I could use a dictionary now !",
"Do or do not, there is no try",
"Tester c'est douter",
"There is no spoon",
"I’m sorry, Dave. I’m afraid I can’t do that.",
"I find your lack of faith disturbing",
"Craftsmanship over crap",
"To iterate is human, to recurse divine.",
"To err is human, but to really foul things up you need a computer.",
"Good design adds value faster than it adds cost.",
"Deleted code is debugged code.",
"implicity is the ultimate sophistication."
};
String fontName = "Monaco";
int fontSize = 20;
PFont font;
float x;
float y;
int frame;
Phrase[] phrases;
int phrasesShown = 23;
class Phrase {
String letters;
int[] opacity;
float xPos;
float yPos;
int position;
int birthDate;
int deathDate;
Phrase(float XX, float YY, String someLetters, int birth) {
letters = someLetters;
xPos = XX;
yPos = YY;
position = -1;
birthDate = birth;
deathDate = birth + int(random(500));
opacity = new int[letters.length()];
for(int i=0;i<letters.length();i++) {
opacity[i] = int(random(130))+126;
}
}
boolean isBorn(int time) {
return birthDate < time;
}
boolean isDying(int time) {
return deathDate - 10 < time;
}
boolean isDead(int time) {
return deathDate < time;
}
boolean isAlive(int time) {
return isBorn(time) && !isDead(time);
}
void display(int time) {
if (!isAlive(frame)) {
return;
}
for(int i=0;i<position;i++) {
int currentOpacity = opacity[i];
if (isDying(time)) {
opacity[i] /=2; // should have some function about time to dim slowly.
}
fill(0, 255, 0, currentOpacity);
text(letters.charAt(i), xPos, yPos+ i*17);
}
if (position < letters.length()) {
fill(255, 255, 255, 255);
text("#", xPos, yPos + (position + 1)*17);
position++;
}
}
}
void setup() {
x = 20;
y = 20;
float oldx = x;
phrases = new Phrase[phrasesShown];
for (int i=0; i< phrasesShown; i++) {
phrases[i] = new Phrase(oldx, y + int(random(height/2)), rawTexts[int(random(rawTexts.length))],int(random(40)));
oldx = oldx + 20 + int(random(30));
}
size(800, 600);
font = createFont(fontName, fontSize, true);
textFont(font, 20);
textAlign(CENTER);
}
void draw() {
background(0);
//scale(frame/100.0);
for (int i=0; i< phrases.length; i++) {
phrases[i].display(frame);
if (phrases[i].isDead(frame)) {
phrases[i] = new Phrase(phrases[i].xPos, y + int(random(height/2)), rawTexts[int(random(rawTexts.length))],int(random(frame+50)));
}
}
filter(BLUR, 1);
displayFrame();
frame++;
}
void displayFrame() {
fill(255, 255, 255, 255);
textFont(font, 30);
text(frame, width - textWidth(""+frame), height-5);
textFont(font, 20);
}