• fullscreen
  • Ball.pde
  • exportInfiniteBubbles.pde
  • class Ball {
      
      float x, y;
      float rayon;
      color coul;
      float vitx = random(0, 2)-1;
      float vity = random(0, 2)-1;
      float vitRayon = random(0, 2);
      
      Ball(){
        x = random(width);
        y = random(height);
        rayon = random(1, 40);
        coul = randCoul();
      }
      
      void drawBall(){
        
        rayon += vitRayon;
        if(rayon>60 || rayon<1){
          vitRayon *= -1; 
        }
        rayon = max(1, rayon);
        
        noStroke();
        
        vitx += (random(0, 2)-1)/5;
        vity += (random(0, 2)-1)/5;
        
        // zone de travail circulaire
        float distRef = dist(x, y, width/2, height/2);
        if(distRef>limiteDist){
          // si on dépasse on retourne petit à petit la vitesse
          float distx = width/2-x;
          float disty = height/2-y;
          vitx += distx/distRef;
          vity += disty/distRef;
        }
        
        x += vitx;
        y += vity;
          
        fill(coul);
        ellipse(x, y, rayon, rayon);
      }
      
    }
    
    int nbBalls = 60;
    Ball[] boule = new Ball[nbBalls];
    // ça c'est un tablo, mais il y a les arrayList qui sont mieux...
    
    float limiteDist = 400;
    
    void setup(){
     smooth();
     size(640, 480); 
     //size(screen.width, screen.height);
     
     colorMode(HSB, 100, 100, 100);
     
     for(int i = 0; i<nbBalls; i++){
       boule[i] = new Ball();
     }
     frameRate(40);
    }
    
    void draw(){
      background(100, 0, 100);
      for(int i = 0; i<nbBalls; i++){
       boule[i].drawBall();
     }
    }
    
    // in setup : colorMode(HSB, 100, 100, 100);
    int baseCoul = round(random(0, 100));
    color randCoul(){
      // Hue / Sat / Bright
      return(color(baseCoul, round(random(30, 70)), round(random(10, 100))));
    }
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Gildas Paubert

    Bubbles

    Add to Faves Me Likey@! 1
    You must login/register to add this sketch to your favorites.

    Un premier essai avec processing : couleur dominante aléatoire, classe Ball, déplacements aléatoires fluides, retour des bulles au delà d'une certaine distance...

    You need to login/register to comment.