> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.S5Iq9JseCxU/rev.1827
 * 
 * authors: 
 *   Kim Seong Jun

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



//CCODE--------------------------
int CODEG;
int CODEG1;
int CODEB;
int Gh;
//REDC---------------------------
int starC;
float fireR;
float fireC;
int fireW;
int fireB;
int fireX; 
int fireY;
int fireZ;
float sX;
float sY;
float sZ;
//BLUEC----------------------------
float x;
float y;
float targetX, targetY;
float easing = 0.05;
int BW;
float UY;
float UX1;
//GREENC---------------------------
int numBalls = 70;
float spring = 0.25;  
float gravity = 0.1;  
Ball[] balls = new Ball[numBalls];  
float GD ;
//WHITEC---------------------------
int WC;
int WC1;
int WD;
 
 
 
 
void setup() {
  size(800,800);
  smooth();
  noCursor();
  background(0);
  fill(255);
  ellipse(400,400,300,300);
  noStroke();
  frameRate(40);
  for (int i = 0; i < numBalls; i++) {  
    balls[i] = new Ball(random(width), random(height), random(75, 40), i, balls);
  }
}
 
//START----------------------------------------------------------------------------
void draw() {
 
  if(sX>398 && sY>398) {
    boom(400,400);
  }
 
  ember();
 
  if(fireR>600 && fireC>500 && fireZ>400) { 
    fireR = 1;
    fireC = 1;
    fireZ = 1;
  }
 
 if(fireW > 3000){
   CODEG = CODEG +5;
   CODEG1 = 100;
    fill(0,255,0,150);
    ellipse(400,400,CODEG,CODEG);
 }
  if(CODEG > 1500) {
    Gh = Gh+6;
    fill(35,89,35);
    ellipse(400,400,Gh,Gh);
  }
  
  if(Gh>1500){
    GH1();
  }


 
  if(CODEG >5000) {
    CODEB = CODEB +10;
    fill(0,0,random(150,255),100);
    ellipse(400,400,CODEB,CODEB);
  }
 
  if(CODEB > 1500) {
    BC();
  }
  
  if(WC>1500){
        Cycle();
        }
  
  
}
 
 
//RED------------------------------------------------------------------------
void ember() {
  sX= sX+3;
  sY= sY+3;
  sZ= random(0,50);
 
  fill(255,random(50,100),0,100);
  ellipse(sX,sY,sZ,sZ);
}
 
 
 
void boom(float fireX, float fireY) {
 
 
  fireW = fireW +5;
  fill(random(150,255),0,0,50);
  ellipse(fireX,fireY,fireW,fireW); 
  for(int cl=0; cl<300;cl=cl+10) {
    fill(255,100);
    ellipse(fireX,fireY,cl,cl);
  }
 
  stroke(255,200); 
  strokeWeight(random(5,20));
  line(400,400,random(0,1000),random(0,1000));
 
  if(fireW>300) {
    fire(random(0,width),random(0,height));
  }
}
 
 
 
 
void fire(float starX, float starY) {
 
  fireC = fireC + 2;
  fireR = fireR + 3;
  fireZ = fireZ + 1;
  noStroke();
  fill(255,random(40,100),0,random(100,250));
  ellipse(starX,starY,fireR,fireR);
  fill(255,100,0);
  ellipse(starX,starY,fireZ,fireZ);
  fill(0,0,0,random(50,150));
  ellipse(random(200,600),random(200,600),fireC,fireC);
}
 
//BLUE-------------------------------------------------------------
void BC() {
  stroke(0,0,255,200); 
  strokeWeight(random(5,20));
 BL();
 BL();
 BL();
  if(CODEB>3000){
      BW = BW +5;
      fill(0,0,random(150,255),255);
      ellipse(400,400,BW,BW);
      }
  if(BW>1500){
      blueUFO();
      }
}   
    
void BL(){
     line(random(0,1000),random(0,1000),400,400);
  line(random(0,1000),random(0,1000),400,400);
  }
  
void blueUFO() {
  background(0,0,random(150,255),255);
  if(key == 'b' || key == 'B'){
  Blue();
  }
  if(key == 'n' || key == 'N'){
   background(0,0,random(150,255),255);
   }
   
  if(key == 'w' || key == 'W'){
    White(255,255,255);
    }   
   
 if(mousePressed){
  stroke(255,200); 
  strokeWeight(random(5,20));
  line(x,y,random(0,1000),random(0,1000));
  line(x,y,random(0,1000),random(0,1000));
  line(x,y,random(0,1000),random(0,1000));
  line(x,y,random(0,1000),random(0,1000));
     }
  UFO(100);
 
}
 
void UFO(float UX){
  
  
  noStroke();
  UY = UX * 1/5;
  
  targetX = mouseX;
  float dx = targetX - x;
  if(abs(dx) > 1) {
    x += dx * easing;
  }
  
  targetY = mouseY;
  float dy = targetY - y;
  if(abs(dy) > 1) {
    y += dy * easing;
  }
  
  
      
  fill(#338AE5);
  ellipse(x, y-(UX * 1/6), UX, UY*3);
  fill(255);
  ellipse(x, y, UX*2, UY*3);
  fill(#195A9D);
  ellipse(x, y+(UX * 1/7), UX, UY*3);
  fill(#C6C112);
  ellipse(x, y-(UX * 1/100), 7 * (UX * 1/100), 4 * (UX * 1/100));
  fill(#C6C112);
  ellipse(x+(UX * 1/5), y-(UX * 1/200), 6  * (UX * 1/100), 3 * (UX * 1/100));
  fill(#C6C112);
  ellipse(x+(UX * 1/3) , y+(UX * 1/100), 5 * (UX * 1/100), 2 * (UX * 1/100));
  fill(#C6C112);
  ellipse(x-(UX * 1/5), y+(UX * 1/200), 6 * (UX * 1/100), 3 * (UX * 1/100));
  fill(#C6C112);
  ellipse(x-(UX * 1/3), y+(UX * 1/50), 5 * (UX * 1/100), 2 * (UX * 1/100));
}
  
void Blue() {
  noStroke();
  background(0);
 
  for(int i=0; i<10; i=i+1) {
    for(int j=0; j<10; j=j+1) {
      BlueR(10+(i*90),10+(j*90));
    }
  }
}
 
void BlueR(float x, float y)
{
  fill(0,0,random(150,255),random(50,255));
  ellipse(x,y,80,80);
}  
 
 
 
//GREEN--------------------------------------------------------------------
void GH1() {
 
  noStroke();
  
  GD = GD + 0.2;
  GH3();
  GH3();

  if(GD >70){
      Green();
      }
      }


void GH2() {
    fill(255,204);
  ellipse(random(20,780),random(20,780),GD,GD);
  ellipse(random(20,780),random(20,780),GD,GD);
  ellipse(random(20,780),random(20,780),GD,GD);
  ellipse(random(20,780),random(20,780),GD,GD);
  }
  
void GH3() {
      GH2();
  GH2();
  GH2();
  GH2();
  GH2();
  
 
  }  

void Green() {
  
  background(35, 89, 35);  
  fill(random(0,255),random(100,255),255);
  for (int i = 0; i < numBalls; i++) {  
    balls[i].collide();  
    balls[i].move();  
    balls[i].display();
  }
}
 
 
 
class Ball {  
  float x, y;  
  float diameter;  
  float vx = 0; 
  float vy = 0;  
  int id; 
  Ball[] others;  
 
  Ball(float xin, float yin, float din, int idin, Ball[] oin) {  
    x = xin;  
    y = yin;  
    diameter = din;  
    id = idin;  
    others = oin;
  }   
 
  void collide() {  
    for (int i = id + 1; i < numBalls; i++) {  
      float dx = others[i].x - x;  
      float dy = others[i].y - y;  
      float distance = sqrt(dx*dx + dy*dy);  
      float minDist = others[i].diameter/2 + diameter/2;  
      if (distance < minDist) {   
        float angle = atan2(dy, dx);  
        float targetX = x + cos(angle) * minDist;  
        float targetY = y + sin(angle) * minDist;  
        float ax = (targetX - others[i].x) * spring;  
        float ay = (targetY - others[i].y) * spring;  
        vx -= ax;  
        vy -= ay;  
        others[i].vx += ax;  
        others[i].vy += ay;
      }
    }
  }  
 
  void move() {  
    vy += gravity;  
    x += vx;  
    y += vy;  
    if (x + diameter/2 > width) {  
      x = width - diameter/2;  
      vx += -0.9;
    }  
    else if (x - diameter/2 < 0) {  
      x = diameter/2;  
      vx *= -0.9;
    }  
    if (y + diameter/2 > height) {  
      y = height - diameter/2;  
      vy *= -0.9;
    }   
    else if (y - diameter/2 < 0) {  
      y = diameter/2;  
      vy *= -0.9;
    }
  }  
 
  void display() {  
    fill(255, 204);  
    ellipse(x, y, diameter, diameter);
  }
}  
void tileelp(float x, float y, float w)
{
  if(mouseX >x && mouseX<x+w && mouseY>y && mouseY<y+w)
  {
    fill(255);
  }
  else {
    fill(#1C9BFF);
  }
  ellipse(x,y,w,w);
} 


//White---------------------------------------------------------------------

void White(float R, float G, float B){
    stroke(R,0,0,200); 
    strokeWeight(random(5,20));
    line(random(0,1000),random(0,1000),400,400);
    stroke(0,G,0,200); 
    strokeWeight(random(5,20));
    line(random(0,1000),random(0,1000),400,400);
    stroke(0,0,B,200); 
    strokeWeight(random(5,20));
    line(random(0,1000),random(0,1000),400,400);
    WC = WC + 5;
    fill(random(0,255),random(0,255),random(0,255),255);
    ellipse(400,400,WC,WC);
    
    
    }
    
void Cycle(){
    
    WC1 = WC1 + 5;
    WD = WD + 3;
    
    fill(255,255);
    ellipse(400,400,WC1,WC1);
    
    ellipse(random(0,800),random(0,800),WD,WD);
    ellipse(random(0,800),random(0,800),WD,WD);
    ellipse(random(0,800),random(0,800),WD,WD);
    ellipse(random(0,800),random(0,800),WD,WD);
        
    if(WC1 > 1500){
      exit();
      }
      }