-
Notifications
You must be signed in to change notification settings - Fork 3
/
StateMachine.pde
120 lines (98 loc) · 2.53 KB
/
StateMachine.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
class StateMachine
{
int NUM_STATES = 9;
StateDrawer drawer;
TransitionState posStates[];
float t = 0;
int currentFinalState;
float totalT;
float lastToggleT;
boolean isMovingBetweenPositionStates;
StateMachine()
{
posStates = new TransitionState[NUM_STATES];
posStates[0] = new RectMoirePositionState("magdaleen.JPG");
posStates[1] = new RectMoirePositionState("vision.jpg");
posStates[2] = new RandomPositionState("roman2.jpg");
posStates[3] = new RectMoirePositionState("ouma.JPG");
posStates[4] = new RectMoirePositionState("vision2.jpg");
posStates[5] = new RectMoirePositionState("amanda.JPG");
posStates[6] = new RandomPositionState("seperate.jpg");
posStates[7] = new RectMoirePositionState("portrait2.JPG");
posStates[8] = new RectMoirePositionState("bed.JPG");
drawer = new StateDrawer(posStates[0]);
drawer.setNextPosState(posStates[1], random(50, 150));
currentFinalState = 1;
isMovingBetweenPositionStates = false;
totalT = 0;
lastToggleT = 0;
}
void updateState()
{
drawer.drawTransition(t);
if (isMovingBetweenPositionStates)
{
t += sound.tInc;
} else
{
t = abs(sound.tInc*50);
}
totalT += sound.tInc;
if (t<0)
t = 0;
//println(t);
if (t>=1)
{
currentFinalState += 1;
currentFinalState = currentFinalState%NUM_STATES;
drawer.setNextPosState(posStates[currentFinalState], random(50, 150));
t = 0;
}
sound.amplifyFactor = getAmplifyFactor(t);
if (totalT-lastToggleT > 1)
{
lastToggleT = totalT;
toggleSize();
toggleMovingBetweenPositionStates();
toggleOffset();
ensureSoundHasEffect();
}
}
void toggleMovingBetweenPositionStates()
{
isMovingBetweenPositionStates = !isMovingBetweenPositionStates;
}
void toggleSize()
{
if (random(0, 1) > 0.5)
sound.varyingSize = !sound.varyingSize;
}
void toggleSpeed()
{
if (random(0, 1) > 0.5)
sound.varyingSpeed = !sound.varyingSpeed;
if (sound.varyingSpeed)
toggleMovingBetweenPositionStates();
else
isMovingBetweenPositionStates = true;
}
void toggleOffset()
{
if (random(0, 1) > 0.2)
sound.varyingOffset = true;
else
sound.varyingOffset = false;
}
void ensureSoundHasEffect()
{
if (!sound.varyingOffset && !sound.varyingSize)
sound.varyingOffset = true;
}
float getAmplifyFactor(float t)
{
if (t<0.5)
return t*2;
else
return (1-t)*2;
}
}