xxxxxxxxxx
/* week 3 from creative coding task. 6.7.2015, Cathal Lindsay.
The background hue can be changed by clicking and dragging. The number of ellpises can be changed by altering 'num'. Changing 'speed' will change the speed of the ellipses. I have added the ability to click on an ellipse to stop it. I have added blurry vibartion to the ellipses.
To be added:1 An offset function to the ellipses to tidy the blur up.
2 : a restart function after a delay to the stopped ellipses.
Note: I still get confused as to where the functions end so i add end comments at the end of a function to remind my self. (i know its messy. But it keeps me right...mostly.)
*/
float radC = random(10);
float red = 120;
float green = 120;
float blue = 120;
void setup() {
size(500, 500);
num = 50;
// allocate space for each array
y = new float[num];
x = new float [num];
speed = new float[num];
phase = new float[num];
// calculate the gap in y based on the number of circles
float gap = height / (num + 1);
//setup an initial value for each item in the array
for (int i=0; i<num; i++) {
y[i] = gap * (i + 1); // y is constant for each so can be calculated once
speed[i] = random(3);
phase[i] = random(PI);
}
}
void draw() {
background(red, green, blue);
for (int i=0; i<num; i++) {
// calculate the x-position of each ball based on the speed, phase and current frame
x[i] = width/2 + sin(radians(frameCount*speed[i] ) + phase[i])* 100;
float radB = random (radC, -radC);//outer ellipse that vibrates
stroke(100);
fill (red/2,green/2,blue/2);
ellipse(x[i], y[i], radB+random(10),radB+random(10));// outer ellipse
fill(red,green,blue);
noStroke();
ellipse(x[i], y[i], radC, radC);
}
}//end draw
// change the background colour if the mouse is dragged
void mouseDragged() {
red = map(mouseX, 0, width, 0, 255);
green = map(mouseY, 0, height, 0, 255);
blue = map(mouseX+mouseY, 0, width+height, 255, 0);
}//endMdrag
//-------click mouse to stop ellipse-----
void mouseClicked(){
for (int i = 0;i < num; i++){
if (dist(mouseX, mouseY, x[i],y[i]) <= radC+3) {
if (speed[i] >0){
speed[i] =0; }//if
fill(red+4,green+4,blue+4);
stroke(red+4,green+4,blue+4);
line(x[i],y[i], mouseX,mouseY);
}//endif
}//endfor
}//endMClikdc