-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimatedText.pde
57 lines (53 loc) · 1.75 KB
/
AnimatedText.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
class AnimatedText {
String text;
String modifiedText;
int currentLetter;
int lastChangeMillis;
int timePerLetter;
int timePerChar;
int lastCharMillis;
public AnimatedText(String text) {
this.text = text;
timePerLetter = 75;
timePerChar = 25;
lastChangeMillis = millis();
lastCharMillis = millis();
modifiedText = "";
}
void update(int x, int y) {
textFont(fontSmall);
if (currentLetter <= text.length() && currentLetter != -1) {
//if (millis()-currentLetter*timePerLetter >= timePerLetter) {
if (millis() - lastChangeMillis >= timePerLetter) {
String tempText = "";
for (int i = 0; i < currentLetter-1; i++) {
tempText += text.charAt(i);
}
if (currentLetter > 0) {
tempText += text.charAt(currentLetter-1);
}
modifiedText = tempText;
if (currentLetter < text.length()) {
currentLetter++;
} else {
currentLetter = -1;
}
lastChangeMillis = millis();
}
if (millis() - lastCharMillis >= timePerChar) {
String obfuscatedText = "";
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890éèêáàâíìîóòôõ$£{}[]!¨ëäïö¦@#°§¬|¢´~+`*ç%&/()=?/<>§°,;.:-_¥⅕⅙⅛⅔⅖⅗⅘⅜⅚⅐⅝↉⅓⅑⅒⅞«»®©™¢€";
int rnd = (int)random(0, chars.length());
for (int i = 0; i < currentLetter-1; i++) {
obfuscatedText += text.charAt(i);
}
obfuscatedText += chars.charAt(rnd);
modifiedText = obfuscatedText;
lastCharMillis = millis();
}
text(modifiedText, x, y);
} else {
text(text, x, y);
}
}
}