I had a look at arrays but I couldn't get my head around them, the code you provided helps though, thanks.
I do get a little bit of play out of it though. Although it seems to be fairly random, the position of the mouse pointer doesn't seem to affect things.
I get
ArrayIndexOutOfBounds Exception: 20 (or
Exception: 21) or
NullPointerException after the code runs for a bit.
Is this trying to call a number outside the array limits? If so how do I stop it, or prevent it from stopping the code running?
I'll try and explain the idea a bit better. I had to build on a previous project (which was the lines) and add interactivity and sound.
I want the colour of the lines to correspond to the tone of sound which is played. Movement of the mouse in the x direction speeds or slows the line generation, and in the y direction will control the volume.
The colour generated is random (with some level of control so that they remain cohesive). The numbers from the colour are calculated to give a number between 0 and 19 which should correspond to the sound file played.
Thanks for your help koogy, really appreciate it.
Code:import ddf.minim.*;
int x1=0; int y1; int rw=10; int rh;
float xMouse;
int d=10;
int low1=50; int up1=100; //colours 1
int low2=130; int up2=200; //colours 2
int low3=100; int up3=204; //colours 3
float time; float run=75; float runInt;
int counter=0;
float tone;
Minim minim;
public static final int NUM_WAVS = 20;
AudioPlayer[] snd = new AudioPlayer[NUM_WAVS];
void setup()
{
size(500,500);
background(255);
noStroke();
smooth();
minim = new Minim(this);
for (int i = 0 ; i < NUM_WAVS ; i++) {
snd[i] = minim.loadFile(i + ".0.wav");
}
}
void draw()
{
time=round(random(0,500)/10)*10;
if ((run-100) <= millis() && (run+100) >= millis())
{
linesRegenerate();
runInt=(mouseX/4)+20;
run=run+runInt;
}
else {println("time false");}
}
void linesRegenerate()
{
for (float xpos=time-d; xpos<time; xpos=xpos+10)
{
y1=mouseY;
rh=2*(250-y1);
fill(255);
rect(xpos,0,rw,500);
float col1=random(low1,up1);
float col2=random(low2,up2);
float col3=random(low3,up3);
fill(col1,col2,col3);
tone=round(((col1+col2+col3)/9.6)-29);
constrain(tone, 0, 19);
rect(xpos,y1,rw,rh);
println(tone+".wav");
snd[(int)tone].loop(0);
}
}
void stop()
{
minim.stop();
super.stop();
}