Changing the colour of the wave in response to the key pressed.
in
Programming Questions
•
1 year ago
Hey guys, I was working on my code when I hit a stumbling block. I am creating a keyboard that creates ripples when a key is pressed, however the problem I am currently facing is that I am unable to make the wave change colour in response to the key being pressed. Please do advise! (ps: i am creating a ripple effect, therefore each time a key is pressed, a new wave is formed, and I want to change the colour of the new wave in accordance to the key that has been pressed.
Here is my code!
class Wave {
PVector loc;
int farOut;
Wave() {
loc = new PVector();
loc.x = 400;
loc.y = 300;
farOut = 1;
}
void update() {
farOut +=4;
}
void display() {
noStroke();
fill(100,200,200);
ellipse(loc.x, loc.y, farOut, farOut);
}
boolean dead() {
if (farOut>1100) {
return true;
}
return false;
}
}
ArrayList<Wave> waves = new ArrayList<Wave>();
import arb.soundcipher.*;
import arb.soundcipher.constants.*;
void setup() {
size(800, 600);
frameRate(30);
ellipseMode(CENTER);
}
SoundCipher sc = new SoundCipher(this);
void draw() {
background(85);
if (keyPressed) {
Wave w = new Wave();
waves.add(w);
}
for (int i = 0; i<waves.size();i++) {
waves.get(i).update();
waves.get(i).display();
if (waves.get(i).dead()) {
waves.remove(i);
}
}
}
void keyPressed()
{
sc.playNote(key - 40, 100, 0.5);
}
1