344
edits
No edit summary |
|||
Line 420: | Line 420: | ||
[[Media: | [[Media:Park2.mp3|Test]] | ||
[[Media:Park3.mp3|Test]] | |||
Processing v2.1.1 Quellcode: | Processing v2.1.1 Quellcode: | ||
<source lang="java"> | <source lang="java"> | ||
import ddf.minim.*; | |||
Minim minim; | |||
PImage img1; | |||
int n=3; | |||
int activeLocation = -1; | |||
AudioPlayer[] players = new AudioPlayer[n]; | |||
int[][] locations = { | |||
{355, 40, 20}, | |||
{335, 165, 20}, | |||
{210, 320, 20}, | |||
}; | |||
void setup() { | |||
minim = new Minim(this); | |||
size(400,600); | |||
img1 = loadImage("https://c2.staticflickr.com/2/1686/24438648251_853287b12c_z.jpg"); | |||
for(int i=0; i<n; i++){ | |||
players[i] = minim.loadFile("https://www.uni-weimar.de/medien/wiki/File:Park" + (i+1) + ".mp3"); | |||
} | |||
} | |||
void draw() { | |||
image(img1,0,0,400,600); | |||
fill(225,150); | |||
noStroke(); | |||
for(int i=0; i < locations.length; i++){ | |||
int[] loc =locations[i]; | |||
int x= loc[0]; | |||
int y= loc[1]; | |||
int r= loc[2]; | |||
if(atLocation(x,y,r)){ | |||
activeLocation = i; | |||
ellipse(x, y, 2*r, 2*r); | |||
} | |||
if(playingLocation(i)){ | |||
ellipse( x,y,2*r,2*r); | |||
} | |||
} | |||
} | |||
boolean atLocation(int x, int y, int r){ | |||
return dist(x,y,mouseX,mouseY)<r; | |||
} | |||
boolean playingLocation(int i){ | |||
return players[i].isPlaying(); | |||
} | |||
void mousePressed(){ | |||
if(activeLocation !=-1){ | |||
for (int i=0; i<n; i++) { | |||
players[i].pause(); | |||
} | |||
println("Sound number " + (activeLocation + 1)); | |||
println(mouseX, mouseY); | |||
players[activeLocation].rewind(); | |||
players[activeLocation].play(); | |||
} | |||
} | |||
void keyPressed(){ | |||
for(int i=0; i<n; i++){ | |||
players[i].pause(); | |||
} | |||
int i = (key - '1'); | |||
if(i>= 0 && i<n){ | |||
println("Sound " + (i+1)); | |||
players[i].rewind(); | |||
players[i].play(); | |||
} | |||
} | |||
</source> | </source> | ||
<br> | <br> |
edits