(Created page with "Processing v2.1.1 Quellcode: <br> <source lang="java"> import ddf.minim.*; Minim minim; PImage img1; int n=3; int activeLocation = -1; AudioPlayer[] players = new AudioPlayer...") |
No edit summary |
||
Line 1: | Line 1: | ||
Processing v2.1.1 Quellcode: | Processing v2.1.1 Quellcode: | ||
<br> | <br> |
Latest revision as of 11:15, 28 January 2016
Processing v2.1.1 Quellcode:
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("http://waesch.host56.com/ablage/sound/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 " + (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();
}
}