forked from League-Archive/IntroToJavaWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessing.pde
More file actions
71 lines (55 loc) · 1.97 KB
/
processing.pde
File metadata and controls
71 lines (55 loc) · 1.97 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
import ddf.minim.*;
Minim minim = new Minim(this);
/**
We're going to use BANANAS to stop and start songs. Different bananas will play different songs.
If you haven't used the Makey Makey before, check out this guide before you start: http://makeymakey.com/howto.php
1. Download a song from : youtube-mp3.org
2. Plug the Makey Makey into the bananas.
3. Finish the Processing code below so that touching a banana will start and stop a song.
**/
AudioPlayer yellowSubmarine;
AudioPlayer yellowSubmarine2; //1. Change to the name of your song
boolean yellowSubmarineIsStopped = true;
boolean yellowSubmarine2IsStopped = true;
void loadSongs() {
yellowSubmarine = minim.loadFile("bob.mp3"); //2. Drop mp3 onto this sketch and put its name here
yellowSubmarine2 = minim.loadFile("ride.mp3"); //2. Drop mp3 onto this sketch and put its name here
}
void keyPressed() {
if (keyCode == UP) {
/* 3. If yellowSubmarineIsStopped, play it, and set yellowSubmarineIsStopped to false. */
if(yellowSubmarineIsStopped == true){
playSong(yellowSubmarine);
yellowSubmarineIsStopped = false; }
/* 4. Otherwise, stop it, and set yellowSubmarineIsStopped to true. */
else {
stopSong(yellowSubmarine);
yellowSubmarineIsStopped = true;
}
}
if (keyCode == DOWN) {
println (keyCode);
/* 3. If yellowSubmarineIsStopped, play it, and set yellowSubmarineIsStopped to false. */
if(yellowSubmarine2IsStopped == true){
playSong(yellowSubmarine2);
yellowSubmarine2IsStopped = false; }
/* 4. Otherwise, stop it, an set yellowSubmarineIsStopped to true. */
else {
stopSong(yellowSubmarine2);
yellowSubmarine2IsStopped = true;
}
/* 5. Add other songs for the other bananas. keyCode will tell you which banana was pressed. */
println("you pressed " + keyCode);
}
}
void playSong(AudioPlayer song) {
song.play();
}
void stopSong(AudioPlayer song)
{
song.pause();
}
void draw() {ellipse(50,50, mouseY,mouseX);}
void setup() {
loadSongs();
}