> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.3N3DBJK7IhD/rev.115
 * 
 * authors: 
 *   ugobagnarosa
 *   

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



int nbGoutte = 20;
SANG[] sang = new SANG[nbGoutte];

PFont f;
String message = "A new challenger has come to the company !yzgduyzgduayhg";
// An array of Letter objects
Letter[] letters;

PFont f2;
String message2 = "A challenger is knocked out and quits the company !";
// An array of Letter objects
Letter2[] letters2;


void setup() {

  size(500, 700);
  background(0);

  // Load the font
  f = createFont("Verdana",11,true);
  textFont(f);
  f2 = createFont("Verdana",11,true);
  textFont(f2);

  // Create the array the same size as the String
  letters = new Letter[message.length()];
  // Initialize Letters at the correct x location
  float x = width/4;
  float y = height-100;
  for (int i = 0; i < message.length(); i++) {
    letters[i] = new Letter(x,y,message.charAt(i),new PVector(random(0.3), random(0.3)),new PVector(x,height/2)); 
    x += textWidth(message.charAt(i));
  }

  // Create the array the same size as the String
  letters2 = new Letter2[message2.length()];
  // Initialize Letters at the correct x location
  float x2 = (width/4)-20;
  float y2 = height/2-200;
  for (int j = 0; j < message2.length(); j++) {
    letters2[j] = new Letter2(x2,y2,message2.charAt(j),new PVector(random(0.3), random(0.3)),new PVector(x2,height/2)); 
    x2 += textWidth(message2.charAt(j));
  }

  for(int i=0; i<nbGoutte ; i++) {
    sang[i] = new SANG(x2,y2,new PVector(random(0.3), random(0.3)),new PVector(x2,height/2));
  }
}

int temps = 17000;
int val = 40;//------------- variable pour la taille des cercles
int col;//------------------ variable pour la couleur des cercles
float modul = 0;

void draw() { 
  //variable temps
  int t = millis() % temps;
  float tailleRond = random(30,50);
  float tailleRond2 = random(5,30);
  
  fill(0);
  rect(0,0,width, height);
  
//////////----------------------------------------------- dessin halo central
  
  modul+=0.1;
  float Modul= noise(modul)*100;
  float val1 = map(Modul ,0, width, 0, Modul);
  float tirage = random(10);
  float l = largeur(val1);// --------------- t est calculé à partir de la fonction largeur(float val1);
  col = 0;
  dessine(l, col);
  
//////////----------------------------------------------- fin halo central
  for (int i = 0; i < 42; i++) {
     if (t <9900) {
      letters[i].display();
      letters[i].shake();
    }
    if (9900<t && t <10000) {
      letters[i].start();
    }
    if (10000<t && t<15000) {
      // Display all letters
      letters[i].display();
      letters[i].home();
    } 
    if (15000< t && t <temps) {
      letters[i].display();
      letters[i].shake();
    }
  }
  
  for (int i = 42; i < letters.length; i++) {
         if (t >9900) {
         letters[i].display();
         letters[i].shake2();
         }
       }

  for (int j = 0; j < letters2.length; j++) {
    // Display all letters

    if (t <100) {
      letters2[j].start();
    }
    if (100<t && t <5000) {
      letters2[j].display();
      letters2[j].shake();
    } 
    if (5000< t && t <10000) {
      letters2[j].display();
      letters2[j].home();
    }  
    if (10000< t && t <temps) {
      letters2[j].display();
      letters2[j].quit();
    }
  }
  
  for (int k = 0; k < nbGoutte; k++) {
    sang[k].affiche();
    sang[k].shake3();
  }
//////////----------------------------------------------- dessin des ronds
  noStroke();
  fill(255,random(50));
  ellipse(random(width/2-20,width/2+20),random(height/2-20,height/2+20),tailleRond,tailleRond);
  fill(255,random(100));
  ellipse(random(width/2-5,width/2+5),random(height/2-5,height/2+5),tailleRond2,tailleRond2);
  ellipse(random(width/2-5,width/2+5),random(height/2-5,height/2+5),tailleRond2+20,tailleRond2+20);
  fill(255,random(80));
  ellipse(random(width/2-5,width/2+5),random(height/2-5,height/2+5),tailleRond2+tailleRond,tailleRond2+tailleRond);
  fill(255,random(80,150));
  ellipse(random(width/2-30,width/2+30),random(height/2-30,height/2+30),tailleRond2,tailleRond2);
  fill(100,40,40,random(190));
  ellipse(random(width/2-50,width/2+50),random(height/2-50,height/2+50),tailleRond2,tailleRond2);
  ellipse(random(width/2-50,width/2+50),random(height/2-50,height/2+50),tailleRond2,tailleRond2);
//////////----------------------------------------------- fin dessin des ronds

}


//////////////////////////////-------------------fonctions récursives pour le dégradé central

float largeur(float val1) {
  int t = millis() % temps;
  modul+=0.1;
  float Modul= noise(modul)*200;
  float mx =120;
  if (5000< t && t <5500) {
  mx =180;
  }
    mx = mx + val1;
  return mx;
}


void dessine(float dVal, int coul) {
  modul+=0.001;
  float Modul= noise(modul)*20;
  fill(coul);
  ellipse(width/2, height/2,dVal, dVal);
  // recursion avec condition permettant d'éviter la boucle infinie : on rappelle la fonction jusqu'à ce la condition ne sois plus remplie
  if(dVal>5) {
    dVal-=4;
    coul+=5+Modul;
    dessine(dVal, coul);
  }
}



class Letter2 {
  char letter;
  // The object knows its original "home" location
  float homex,homey;
  // As well as its current location
  float x,y;
  // And an angle of rotation
  float theta;
  float Modul=random(360);
  
  PVector position;//------------------------------------------- on ajoute les variables PVector pour faciliter 
  //------------------------------------------------------------ les calculs de déplacements
  PVector velocite;//------------------------------------------- vitesse 
  PVector acceleration;//--------------------------------------- accélération qui influe sur la vitesse.
  int limiteVitesse = 5;//-------------------------------------- limite de vitesse 
 
  
  Letter2 (float x_, float y_, char letter_,PVector i,PVector v){
    homex = x = x_;
    homey = y = y_;
    x =width/2;
    y =height/2;
  //  theta = random(TWO_PI);
    letter = letter_;
    position = v.get();
    velocite = i.get();
    
  }

  // Display the letter
  void display() {
    int t = millis() % temps;
    if(13000< t && t <temps){
    fill(255,255-((255*t)/temps)); 
    }else{
    fill(200);}
    textAlign(LEFT);
    // User translate and rotate to draw the letter
    pushMatrix();
    translate(x,y);
  //  rotate(theta);
    text(letter,0,0);
    popMatrix();
  }

  // Move the letter randomly
  void shake() {
    position.x = x;
    position.y = y;
    PVector pointeur = new PVector(width/2,height/2);//------------ la cible des poux.
    PVector dir = PVector.sub(pointeur, position);//------------ vecteur de direction pour les poux.
    dir.normalize();//------------------------------------------ on normalise le vecteur à 1
    dir.mult(1);//-------------------------------------------- on diminue encore la précision du vecteur, assoupi les mvts.
    acceleration = dir;//--------------------------------------- l'accélération est fonction de la direction
    velocite.add(acceleration);//------------------------------- on ajoute l'acceleration à la vitesse
    velocite.limit(11);//---------------------------- on limite la vitesse
    position.add(velocite);//----------------------------------- on ajoute la vitesse à la position.
    
    x = position.x;
    y = position.y;
    Modul += 0.0001;
   //   theta = noise(degrees(Modul))*7;
  }
  
   
  void quit() {
    position.x = x;
    position.y = y;
    PVector pointeur = new PVector(x,y);//------------ la cible des poux.
    PVector dir = PVector.sub(pointeur, position);//------------ vecteur de direction pour les poux.
    dir.normalize();//------------------------------------------ on normalise le vecteur à 1
    dir.mult(1.3);//-------------------------------------------- on diminue encore la précision du vecteur, assoupi les mvts.
    acceleration = dir;//--------------------------------------- l'accélération est fonction de la direction
    velocite.add(acceleration);//------------------------------- on ajoute l'acceleration à la vitesse
    velocite.limit(11);//---------------------------- on limite la vitesse
    position.add(velocite);//----------------------------------- on ajoute la vitesse à la position.
    
    
    
    x = position.x;
    y = position.y;
   //Modul += 0.0001;
   //theta = noise(degrees(Modul))*7;
   
    
   
  }

  // Return the letter home using lerp!
  void home() {     
    x = lerp(x,homex,0.1);
    y = lerp(y,homey+random(20),0.1);
  }
  
  void start() {
      x = random(width/2-20,width/2+20);
      y = random(height/2-20,height/2+20);  
      
      
  }
}


// A class to describe a single Letter
class Letter {
  char letter;
  // The object knows its original "home" location
  float homex,homey;
  // As well as its current location
  float x,y;
  // And an angle of rotation
  float theta;
  float Modul=random(360);
  
  PVector position;//------------------------------------------- on ajoute les variables PVector pour faciliter 
  //------------------------------------------------------------ les calculs de déplacements
  PVector velocite;//------------------------------------------- vitesse 
  PVector acceleration;//--------------------------------------- accélération qui influe sur la vitesse.
  int limiteVitesse = 5;//-------------------------------------- limite de vitesse 
 
  
  Letter (float x_, float y_, char letter_,PVector i,PVector v){
    homex = x = x_;
    homey = y = y_;
    x =width/2;
    y =height/2;
  //  theta = random(TWO_PI);
    letter = letter_;
    position = v.get();
    velocite = i.get();
    
  }

  // Display the letter
  void display() {

    fill(200);
    textAlign(LEFT);
    // User translate and rotate to draw the letter
    pushMatrix();
    translate(x,y);
  //  rotate(theta);
    text(letter,0,0);
    popMatrix();
  }

  // Move the letter randomly
  void shake() {
    position.x = x;
    position.y = y;
    PVector pointeur = new PVector(random(width/2-50,width/2+50),random(height/2-50,height/2+50));//------------ la cible des poux.
    PVector dir = PVector.sub(pointeur, position);//------------ vecteur de direction pour les poux.
    dir.normalize();//------------------------------------------ on normalise le vecteur à 1
    dir.mult(0.8);//-------------------------------------------- on diminue encore la précision du vecteur, assoupi les mvts.
    acceleration = dir;//--------------------------------------- l'accélération est fonction de la direction
    velocite.add(acceleration);//------------------------------- on ajoute l'acceleration à la vitesse
    velocite.limit(limiteVitesse);//---------------------------- on limite la vitesse
    position.add(velocite);//----------------------------------- on ajoute la vitesse à la position.
    
    x = position.x;
    y = position.y;
    Modul += 0.0001;
   //   theta = noise(degrees(Modul))*7;
  }
  
  void shake2() {
    position.x = x;
    position.y = y;
    PVector pointeur = new PVector(random(width/2-10,width/2+10),random(height/2-10,height/2+10));//------------ la cible des poux.
    PVector dir = PVector.sub(pointeur, position);//------------ vecteur de direction pour les poux.
    dir.normalize();//------------------------------------------ on normalise le vecteur à 1
    dir.mult(0.8);//-------------------------------------------- on diminue encore la précision du vecteur, assoupi les mvts.
    acceleration = dir;//--------------------------------------- l'accélération est fonction de la direction
    velocite.add(acceleration);//------------------------------- on ajoute l'acceleration à la vitesse
    velocite.limit(11);//---------------------------- on limite la vitesse
    position.add(velocite);//----------------------------------- on ajoute la vitesse à la position.
    
    x = position.x;
    y = position.y;
    Modul += 0.0001;
   //   theta = noise(degrees(Modul))*7;
  }
   
  void quit() {
    position.x = x;
    position.y = y;
    PVector pointeur = new PVector(x,y);//------------ la cible des poux.
    PVector dir = PVector.sub(pointeur, position);//------------ vecteur de direction pour les poux.
    dir.normalize();//------------------------------------------ on normalise le vecteur à 1
    dir.mult(1.3);//-------------------------------------------- on diminue encore la précision du vecteur, assoupi les mvts.
    acceleration = dir;//--------------------------------------- l'accélération est fonction de la direction
    velocite.add(acceleration);//------------------------------- on ajoute l'acceleration à la vitesse
    velocite.limit(11);//---------------------------- on limite la vitesse
    position.add(velocite);//----------------------------------- on ajoute la vitesse à la position.
    
    
    
    x = position.x;
    y = position.y;
   //Modul += 0.0001;
   //theta = noise(degrees(Modul))*7;
   
    
   
  }

  // Return the letter home using lerp!
  void home() {
      
    x = lerp(x,homex,0.1);
    y = lerp(y,homey,0.1);
  }
  
  void start() {

      x = random(width/2-20,width/2+20);
      y = random(height,height+20);  
      
      
  }
}



// A class to describe a single Letter
class SANG {
  char letter;
  // The object knows its original "home" location
  float homex,homey;
  // As well as its current location
  float x,y;
  // And an angle of rotation
  float theta;
  float acc;
  float Modul = 0;

  PVector position;//------------------------------------------- on ajoute les variables PVector pour faciliter 
  //------------------------------------------------------------ les calculs de déplacements
  PVector velocite;//------------------------------------------- vitesse 
  PVector acceleration;//--------------------------------------- accélération qui influe sur la vitesse.
  int limiteVitesse = 5;//-------------------------------------- limite de vitesse 
  
  int t = millis() % temps;

  SANG (float x_, float y_,PVector i,PVector v) {
    homex = x = x_;
    homey = y = y_;
    x = random(width);
    y = random(height);
    //  theta = random(TWO_PI);
    position = v.get();
    velocite = i.get();
  }

  // Display the letter
  void affiche() {
    fill(255);
   // textAlign(LEFT);
    // User translate and rotate to draw the letter
    pushMatrix();
    translate(x,y);
    popMatrix();
    noStroke();
    fill(255);
    //point(x,y);
    ellipse(x,y,1+acc,1+acc); 
  }

  // Move the letter randomly
  void shake3() {
       
    if(5000< t && t <10000){
      Modul += 0.001;
      acc = noise(Modul)/10;
      limiteVitesse = int(noise(Modul)*10);
     }else{Modul += 0.1;
      acc = noise(Modul)/2;
     }
    
    position.x = x;
    position.y = y;
    PVector pointeur = new PVector(random(width/2-50,width/2+50),random(height/2-50,height/2+50));//------------ la cible des poux.
    PVector dir = PVector.sub(pointeur, position);//------------ vecteur de direction pour les poux.
    dir.normalize();//------------------------------------------ on normalise le vecteur à 1
    dir.mult(acc);//-------------------------------------------- on diminue encore la précision du vecteur, assoupi les mvts.
    acceleration = dir;//--------------------------------------- l'accélération est fonction de la direction
    velocite.add(acceleration);//------------------------------- on ajoute l'acceleration à la vitesse
    velocite.limit(limiteVitesse);//---------------------------- on limite la vitesse
    position.add(velocite);//----------------------------------- on ajoute la vitesse à la position.

    x = position.x;
    y = position.y;
    //
    //   theta = noise(degrees(Modul))*7;
  }

}