Processing: Ghosting Circles
I recently wrote a neat little program in processing that allows a user to place circles (by clicking the screen) and move them around by dragging the mouse. Each circle leaves a ghostly trail behind it as it moves. Paste the code into processing to experience it yourself!!!
-------
/* Sean's circle tracking extravaganza! it's the winningest!
* In this program, the user can click anywhere on
* screen and a ball of random color and size will
* appear on the screen! when the user moves the
* mouse around, the balls will move with some
* random correlation to the mouse movement
*
*/
//number of circles
int numCircs = 30;
circle[] circArray = new circle[numCircs];
void setup() {
//initialize all the circles
for(int i = 0; i < numCircs; i++) {
circArray[i] = new circle();
}
size(1024,768);
background(0);
fill(random(255),random(255),random(255));
noStroke();
//you can adjust the frame rate if you want O_O_O_O
//frameRate(100);
}
void draw() {
translate(1024/2, 768/2);
background(0);
for (int i = 0; i
}
}
void mousePressed() {
//draw an ellipse with a random size
for (int i = numCircs-1; i>0 ; i--) {
circArray[i]=circArray[i-1];
}
circArray[0] = new circle(mouseX-1024/2, mouseY-768/2, random(10,45), random(-2,2), random(-2,2), int(random(10,80)));
}
class circle {
float[] xPos;
float[] yPos;
float radius;
float factorX;
float factorY;
int numTrail;
int trackme = 0;
float c1 = random(255);
float c2 = random(255);
float c3 = random(255);
circle() {
numTrail = 1;
xPos = new float[numTrail];
yPos = new float[numTrail];
for(int i = 0; i
yPos[i] = 0;
}
radius = 0;
factorX = 0;
factorY = 0;
}
circle(float x,float y,float r,float fx, float fy, int Trails) {
numTrail = Trails;
xPos = new float[numTrail];
yPos = new float[numTrail];
for(int i = 0; i
yPos[i] = y;
}
radius = r;
factorX = fx;
factorY = fy;
}
void update() {
trackme++;
rotate(PI*trackme*factorX*.5/4000);
float mouseChangeX = mouseX-pmouseX;
float mouseChangeY = mouseY-pmouseY;
// Reads throught the entire array
// and shifts the values to the left
for(int i=1; i
yPos[i-1] = yPos[i];
}
// Add the new values to the end of the array
xPos[numTrail-1] += mouseChangeX*factorX;
yPos[numTrail-1] += mouseChangeY*factorY;
fill(c1,c2,c3, 28);
for(int i=0; i
ellipse(xPos[i], yPos[i], divisor, divisor);
}
}
}