Hi again. I have this working in a basic way now...
But there are a couple of problems.
1. When you hold down a key, loads get spawned at the same time (as you'd expect) but this is an undesired effect. Is there some sort of simple 'dampening' I can use - ie. "if a pulse has been spawned within 500ms (or whatever) don't spawn a new one" to avoid this continuous repeating.
2. I'm thinking that expanding the array isn't the most efficient way. These shockwaves will react to the kick drum sound in music, so I can't imagine there would be more than 10 or 20 on screen at once (probably no-where near that number actually). But how could I make an array that is say 25 long but which cycles through the array and gives the same effect? Expanding by 1 will eventually cause an out of memory error won't it?
Code: import processing.opengl.*;
float radius;
PulseCircle pulse[] = new PulseCircle[0];
PImage pulseCircleImg;
int PulseCircleCount = 1;
void setup() {
size(400,400,OPENGL);
hint( ENABLE_OPENGL_4X_SMOOTH );
textureMode(NORMALIZED);
pulseCircleImg = loadImage( "glowCircleThin.png" );
}
void draw() {
background(0);
translate(width/2, height/2);
if( keyPressed ) {
pulse = (PulseCircle[]) expand(pulse, pulse.length+1);
pulse[pulse.length-1] = new PulseCircle(0,0);
println(pulse.length);
}
for(int i = 0; i < pulse.length; ++i) {
pulse[i].update();
pulse[i].display();
}
}
class PulseCircle {
float x, y;
float pulseRadius;
boolean on = false;
// Constructor
PulseCircle(float xpos, float ypos) {
x = xpos;
y = ypos;
on = true;
pulseRadius = 0;
println("PulseCircle");
}
void start(float xpos, float ypos) {
x = xpos;
y = ypos;
println("Start");
}
void update() {
if (on == true) {
pulseRadius += 5;
println("Update : True");
}
if (pulseRadius > 200) {
pulseRadius = 0;
on = false;
println("Update : False");
}
}
void display() {
if (on == true) {
pushMatrix();
beginShape();
//fill(255);
texture(pulseCircleImg);
vertex(-(pulseRadius), -(pulseRadius), 0, 0, 0);
vertex((pulseRadius), -(pulseRadius), 0, 1, 0);
vertex((pulseRadius), (pulseRadius), 0, 1, 1);
vertex(-(pulseRadius), (pulseRadius), 0, 0, 1);
endShape();
popMatrix();
//fill(255);
//ellipse(0,0,pulseRadius,pulseRadius);
println("Display");
}
}
}