-
Notifications
You must be signed in to change notification settings - Fork 1
/
Letter.pde
65 lines (58 loc) · 1.56 KB
/
Letter.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
class Letter {
int index; //just a good thing to know, used for debugging
int xOffset; //offset horizontally of letter registration
float speed; //speed
char c; //what letter am i
float curYPos, prevYPos; //current and previous y position. used for easing.
int state = 0; // we use a tiny state switcher to control the flow. either the letter is falling or it isn't
float topBrightPixel;//get top bright pixel;
Letter(int index_,int xOffset_,char c_) {
index = index_;
xOffset = xOffset_;
c = c_;
curYPos = int(random(-200,-100));//set currentYPos somewhere above the video
speed = int(random(5,12));
}
void draw() {
senseBrightness();
compareToCurrent();
update();
text(c,xOffset,curYPos);
}
void senseBrightness() {
topBrightPixel = 0;
for(int i = xOffset; i < flip.pixels.length-flip.width*sampleFloor; i+=flip.width) {
if(brightness(flip.pixels[i]) < thresh) {
break;
}
topBrightPixel++;
}
}
void compareToCurrent() {
if (topBrightPixel > curYPos + 2*speed || topBrightPixel >= flip.height - sampleFloor) {
state = 0;
//speed = random(5,12);
} else {
state = 1;
}
}
void update() {
switch (state) {
case 0:
fill (fallColor);
curYPos+=speed;
speed = speed * 1.02;
if (curYPos > height + 50) {
curYPos = random(-50,-200);
speed = random(5,12);
}
break;
case 1:
fill(activeColor);
curYPos += .6* (topBrightPixel - prevYPos);
speed = random(5,12);
break;
}
prevYPos = curYPos;
}
}