-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLetterDisplay.pde
More file actions
186 lines (150 loc) · 5.38 KB
/
LetterDisplay.pde
File metadata and controls
186 lines (150 loc) · 5.38 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//***************************************************************************************************************************************
// LetterDisplay
// This class handles the showing the image and sound for each letter
//***************************************************************************************************************************************
class LetterDisplay {
private Maxim maxim;
private int stage; // stage of display. 0 for moving in, 1 for stationary, 2 for moving away
private int scale; // relative scale of image
private int fullWidth; // Maximum image width
private int fullHeight; // Maximum image height
// Last letter used.
private int lastLetter = 26;
// This will store the audio clips
private short[][] AudioClips = new short [lastLetter][];
// Audio Files
private String[] audioFileArray = {"LtrA96K.wav","LtrB32K.wav",
"LtrC48K.wav","LtrD16K.wav",
"LtrE.wav","LtrF.wav",
"LtrG.wav","LtrH.wav",
"LtrI.wav","LtrJ.wav",
"LtrK.wav","LtrL.wav",
"LtrM.wav","LtrN.wav",
"LtrO.wav","LtrP.wav",
"LtrQ.wav","LtrR.wav",
"LtrS.wav","LtrT.wav",
"LtrU.wav","LtrV.wav",
"LtrW.wav","LtrX.wav",
"LtrY.wav","LtrZ.wav"};
// Image files
private String[] imageArray = {"Letter-A-blue-icon.png","Letter-B-blue-icon.png",
"Letter-C-blue-icon.png","Letter-D-blue-icon.png",
"Letter-E-blue-icon.png","Letter-F-blue-icon.png",
"Letter-G-blue-icon.png" ,"Letter-H-blue-icon.png",
"Letter-I-blue-icon.png","Letter-J-blue-icon.png",
"Letter-K-blue-icon.png","Letter-L-blue-icon.png",
"Letter-M-blue-icon.png", "Letter-N-blue-icon.png",
"Letter-O-blue-icon.png","Letter-P-blue-icon.png",
"Letter-Q-blue-icon.png","Letter-R-blue-icon.png",
"Letter-S-blue-icon.png" ,"Letter-T-blue-icon.png",
"Letter-U-blue-icon.png","Letter-V-blue-icon.png",
"Letter-W-blue-icon.png","Letter-X-blue-icon.png",
"Letter-Y-blue-icon.png" ,"Letter-Z-blue-icon.png"
};
// this will be the AudioPlayer that handles the sounds.
private AudioPlayer player;
// this will contain an array of all the letter images
private PImage[] Letter = new PImage[lastLetter];
private PImage currentLetter;
// Index into letters.
private boolean random = false; // determine weather or not to generate display letters randomly or incrementally
private boolean retreat = false; // Indicates whether image is retreating from the screen
private int step = 0;
private int start = 0; // start position;
private int myIndex = -1; // start index. -1 in case we are incrementing so we can start at A
// constructor for LetterDisplay
public LetterDisplay(PApplet processing){
maxim = new Maxim( );
player = maxim.createEmptyPlayer();
player.loadAudioClips(audioFileArray);
for(int i = 0;i<lastLetter;i++) {
Letter[i] = loadImage(imageArray[i]);
}
ChangeLetter();
}
public void startMovingLetterIn(){
stage = 0;
scale = 60;
}
public void movingLetterIn(){
scale--;
if(scale == 1){
finishedMovingLetterIn();
}
}
public void finishedMovingLetterIn(){
stage = 1;
sayLetter();
scale = 1;
}
public void startMovingLetterOut(){
stage = 2;
scale = 1;
}
public void movingLetterOut(){
scale++;
if(scale == 60){
finishedMovingLetterOut();
}
}
public void finishedMovingLetterOut(){
stage = 0;
ChangeLetter();
scale = 60;
}
public void sayLetter() {
// Load new letter sound into player
player.selectAudioClip(myIndex);
// Play letter sound
player.setLooping(false);
player.volume(1);
player.cue(0);
player.speed(1);
player.play();
}
public void ChangeLetter(){
if(random) {
int lastIndex = myIndex;
// Get random number between 0 and last letter
// Avoid repeating letters
while(myIndex == lastIndex){
myIndex = int(random (lastLetter));
}
}else{
myIndex++;
if(myIndex > 25){
myIndex = start;
}
}
currentLetter = Letter[myIndex];
startMovingLetterIn();
}
public void updateDisplay(){
if(stage != 1)
{
// code that happens every frame
background(0);
// Ensure image is centered
imageMode(CENTER);
float xtran = map(scale,60, 1,0, width/2);
float ytran = map(scale,60, 1,0, height/2);
translate(width/2, height/2);
//translate(xtran,ytran);
if(stage == 0){
movingLetterIn();
}else{
movingLetterOut();
}
float rotation;
if((scale == 1)||(scale==60))
{
rotation = 0;
} else{
//rotate(TWO_PI/15*scale);
}
// paste letter
//scale (1.0/scale);
image(currentLetter,0,0,(width-10)/scale, (height-10)/scale);
}
}
}