-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuitarHeroLite.java
30 lines (24 loc) · 1.04 KB
/
GuitarHeroLite.java
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
public class GuitarHeroLite {
public static void main(String[] args) {
// create two guitar strings, for concert A and C
double CONCERT_A = 440.0;
double CONCERT_C = CONCERT_A * Math.pow(1.05956, 3.0);
GuitarString stringA = new GuitarString(CONCERT_A);
GuitarString stringC = new GuitarString(CONCERT_C);
while (true) {
// check if the user has typed a key; if so, process it
if (StdDraw.hasNextKeyTyped()) {
char key = StdDraw.nextKeyTyped();
if (key == 'a') { stringA.pluck(); }
else if (key == 'c') { stringC.pluck(); }
}
// compute the superposition of samples
double sample = stringA.sample() + stringC.sample();
// play the sample on standard audio
StdAudio.play(sample);
// advance the simulation of each guitar string by one step
stringA.tic();
stringC.tic();
}
}
}