Hi! So I have this code written so far. I'm having trouble with two parts of it: 1. I cannot get the text BREATHE to reappear when mouse is released, it's only a white screen and 2. I cannot get the sound file studentunion.wav to play only when the mouse is Pressed and the sound file calmsound.wav to play when the mouse is not pressed. I'm sure it's something really simple but here is my code so far:
PFont font; float x1 = 0.0; float x2 = 500.0;
import ddf.minim.*; Minim minim; AudioPlayer player; AudioInput input;
//starting information, imput needed int ballCount = 600; int ballSize = 45; int ballSpeed = 2;
float[]xspeed = new float[ballCount]; float[]yspeed= new float[ballCount]; float[]xpos = new float[ballCount]; float[]ypos = new float[ballCount]; float[]wdth = new float[ballCount]; float[]ht = new float[ballCount];
//initialize sketch void setup(){ size(500, 500); background(0);
//Sound
minim = new Minim(this);
player1 = minim.loadFile("calmsound.wav");
player2 = minim.loadFile("studentunion.wav");
input = minim.getLineIn();
//FONT font = createFont("Arial", 250); textFont(font); fill(0);
//BALLS //starting values for all balls
for (int i=0; i<ballCount; i++){
//varied ball speed
xspeed[i] = random(5, ballSpeed);
yspeed[i] = random(-ballSpeed, ballSpeed);
//varied ball sizes
wdth[i]= random(1, ballSize);
ht[i]= wdth[i];
//starting ball placement
xpos[i] = width/3+random(-width/3, width/3);
ypos[i] = height/2+random(-height/3, height/3);
}
// no shape stroke
noStroke();
//ball loop speed
frameRate(40);
}
void draw(){ background(255); //FONT text("breathe", x1, 250); text("breathe", x2, 350); x1 += 1.0; if (x1 > 500) { x1 = -150; } x2 -=0.8; if (x2 < -150) { x2 = 100; }
//when mouse Pressed, balls appear
if(mousePressed == true){
for ( int i = 0 ; i < ballCount ; i++){
//makes the balls move faster when mouse is dragged over them
for (int x = 100; x < width ; x += 100) {
float mx = mouseY /30 ;
float offsetA = random(-mx, mx); float offsetB = random(-mx, mx); strokeCap(ELLIPSE); fill(i*255/ballCount); ellipse(xpos[i], ypos[i], wdth[i], ht[i]);
//calling to array list to change speed of balls
xpos[i]+=xspeed[i];
ypos[i]+=yspeed[i];
//detects ball collision with sketch window edges
//accounting for ball thickness.
if (xpos[i]+wdth[i]/2>=width || xpos[i]<=wdth[i]/2){
xspeed[i]*=-1;
}
if (ypos[i]+ht[i]/2>=height || ypos[i]<=ht[i]/2){
yspeed[i]*=-1;
//Sound
void mousePressed(){
player1.play();
player2.play(); }
void mouseReleased(){
player1.close();
player2.close();
//since close closes the file, we'll load it again player1 = minim.loadFile("calmsound.wav"); player2 = minim.loadFile("studentunion.wav"); } } } } } }