• fullscreen
  • _110321_ballbounce.pde
  • ArrayList ball_list;
    
    Ball myBall;
    
    void setup(){
     size(600,300); 
     ball_list = new ArrayList();
     ball_list.add(new Ball());
    
     noStroke();
     smooth();
     frameRate(30);
    }
    
    void draw()
    {
       background(255);
       fill(0);
       
       for(int i=ball_list.size()-1; i>=0; i--){
         Ball myBall = (Ball) ball_list.get(i);
         myBall.display();
         myBall.move();  
       }
    
    }
    
    class Ball {
      
      float r,g,b;
      float x;
      float y = 310;
      float speed = 20;
      float d = 1;
      int times = 0;
      
      Ball(){
         r = random(255);
         g = random(255);
         b = random(255);
         x = random(500); 
      }
     
      void move(){
        
        if((times < 3)){
        y = y - speed*d;
        speed = speed - 0.9*d;
          
            if((y > height)){
                d = d * - 1;       
                speed = speed * 0.8;
                times++;
            }      
        }
    
        else  
          y = y - speed * d * -1;
      
    
      }
      
      void display(){
         fill(r,g,b);    
         ellipse(x,y,40,40); 
      }     
    }
    
    
    void mousePressed(){
       ball_list.add(new Ball()); 
    }
    
    
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    yongcheon.kim

    ball bouncing

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

    If you pressed the mouse button, you can see the ball.

    You need to login/register to comment.