/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.vvYplE2wW$T/rev.1311
*
* authors:
* alexsmith540
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// This sketch builds on a prior work, "Bubbles", created by alexsmith540
// http://studio.sketchpad.cc/sp/pad/view/ro.98H6j8Mr4kjrE/rev.841
// Pressing Control-R will render this sketch.
ArrayList bubbles;
Bubble bub;
int ron=1;
float mD,mD2;
mD = 1;
mD2 = 1;
void setup() { // this is run once.
ellipseMode(CENTER);
bubbles = new ArrayList;
for(i=0;i<=80;i++){
bubbles.add(new Bubble());
}
ellipseMode(CENTER);
// set the background color
background(255);
// canvas size (Variable aren't evaluated. Integers only, please.)
size(600, 600);
// smooth edges
smooth();
// limit the number of frames per second
frameRate(30);
// set the width of the line.
}
void mousePressed(){
ron = ron == 1 ? 0 : 1;
}
void mouseReleased(){
//ron = 0;
}
void draw() { // this is run repeatedly.
translate(width/2, height/2);
background(255);
int sz = bubbles.size()-1;
for(i=0;i<sz;i++){
bub = bubbles.get(i);
bub.run();
}
}
class Bubble{
float rstart1;
float rstart2;
float randnum,randnum2;
float spin;
int direction;
float effectrate;
int maxsize;
color coll;
Bubble(){
spin = 0;
rstart1 = random(-300,300);
rstart2 = random(-300,300);
randnum = random(50,200);
randnum2 = random(50,200);
direction = 0;
effectrate = random(0,1)*10;
maxsize = random(300,600);
coll = color(random(0,5),random(0,75),random(200,255));
}
void run(){
randnum2 += direction == 0 ? cos(random(0,1))*effectrate:sin(random(0,-1))*effectrate;
direction = abs(randnum2) >= height*0.8 ? (randnum2 < 0 ? 0 : 1):direction;
randnum += direction == 0 ? cos(random(0,1))*effectrate:sin(random(0,-1))*effectrate;
direction = abs(randnum2) >= maxsize ? (randnum2 < 0 ? 0 : 1):direction;
rstart1 += direction == 0 ? random(0,1) : (rstart1 > 0 ? random(0,-1) : random(0,1) );
rstart2 += direction == 0 ? random(0,1) : random(0,-1);
//randnum += cos(random(0,1)*400) > 0 ? cos(random(0,1)*400) : ( randnum > 50 ? cos(random(0,1)*400)*10 : 3 ) ;
strokeWeight(random(0,1));
fill(coll,20);
if(ron == 0){
spin += spin > 0 ? -0.001 : 0;
pushMatrix();
rotate(degrees(spin));
ellipse(rstart1*mD,rstart2*mD2,randnum,randnum2);
popMatrix();
}
else{
rotateall();
}
}
void rotateall(){
//spin += random
//if(spin >= 0.002){direction = direction == 0 ? 1 : 0;}
spin += random(0,1)*0.001*effectrate;
pushMatrix();
// rstart1 += random(1,5);
ron = spin <= 1 ? 1 : 0;
rotate(degrees(spin));
ellipse(rstart1,rstart2,randnum,randnum2);
popMatrix();
}
}