Adding Color and music to Ripple effect

Hi im trying to create a ripple using mouse dragged. i have the code but i dont know how to change the color im hopping to have it be random whenever its dragged across, and for it to play music and stop once the mouse is released.

int cols=200;
int rows=200;
float[][] current= new float [cols][rows];
float[][] past= new float [cols][rows];
float damp=0.999;
void setup()
{
size(1000,1000);
cols=width;
rows=height;
current= new float [cols][rows];
past= new float [cols][rows];
}

void draw()
{
background(0);
loadPixels();
for(int i=1;i<cols-1; i++){
for(int j=1; j<cols-1; j++){

  current[i][j]  = (past[i-1][j]
  +past[i+1][j]
                    +past[i][j-1]+past[i][j+1])/2-
                     current[i][j];  
                     int b=i+j*cols;
                     float c=random(255);
                     current[i][j]=current[i][j]*damp;
                     pixels[b]= color(current[i][j]);

}
}

updatePixels();
float [][] temp=past;
past=current;
current=temp;
}

void mouseDragged(){
past[mouseX][mouseY]=500;

}

Inside the for loops you appoint a colour to a pixel:

pixels[b]= color(current[i][j]);

Because it’s only one value, it becomes a grey colour. Add two more values and you’ll have colour:

pixels[b]= color(current[i][j], 0, 0);

You could replace these 0’s work with a global value that randomises each time you drag the mouse.

I tried doing that earlier but it just randomized all the pixels on the screen not just those on the ripple effect

I see, it seems like my assumption of global variables isn’t working.

Another option is to save the ripple pixels to a PImage, and alter its colour with tint at the end of void draw. Easy to implement, but perhaps not the best solution performance wise.

I just tested your Code on IOS and you might want to use pixels[b] = color(constrain(current[i][j],0,255)); because i got some random white spots inbetween and this removes them.

As for random color, i tried playing around with noise, but it only gives it a purple tint…