/**
* Pulses
*
*
Elie Zananiri
* CART 253, Winter 2008
*/
// ----------------------------------------------------------------------
// GLOBAL CONSTANTS
// ----------------------------------------------------------------------
int MAX_PULSES = 500;
int X = 0;
int Y = 1;
int CURR = 0;
int SCALE = 1;
// ----------------------------------------------------------------------
// GLOBAL VARIABLES
// ----------------------------------------------------------------------
int numPulses = 0;
int[][] pos = new int[MAX_PULSES][2]; // stores all the coordinates
float[][] s = new float[MAX_PULSES][2]; // stores all the size values
// ----------------------------------------------------------------------
// BUILT-IN FUNCTIONS
// ----------------------------------------------------------------------
void setup() {
size(400, 400);
smooth();
noStroke();
}
void draw() {
background(0);
// draw all the pulses
for (int i=0; i < numPulses; i++) {
drawPulse(i);
}
}
void mousePressed() {
addPulse(mouseX, mouseY);
}
void mouseDragged() {
addPulse(mouseX, mouseY);
}
void keyPressed() {
if (key == 32) { // space bar
// clear all
numPulses = 0;
}
}
// ----------------------------------------------------------------------
// USER FUNCTIONS
// ----------------------------------------------------------------------
/* draws a pulse and updates its size */
void drawPulse(int index) {
fill(255);
ellipse(pos[index][X], pos[index][Y], sin(s[index][CURR])*s[index][SCALE], sin(s[index][CURR])*s[index][SCALE]);
s[index][CURR] += 0.1;
}
/* adds a new pulse to the list */
void addPulse(int newX, int newY) {
if (numPulses < MAX_PULSES) {
pos[numPulses][X] = newX;
pos[numPulses][Y] = newY;
s[numPulses][CURR] = 0;
s[numPulses][SCALE] = dist(mouseX, mouseY, pmouseX, pmouseY)+1;
numPulses++;
}
}