Anyone know how to get multiple circles to fall from the top of the screen on a mouse/key press?

I'm trying to create a showerhead effect where small blue circles fall from a static bigger "hose," but as a new coder, I am unsure as to how to get simple shapes to fall from the top of the screen on a mouse press. It would be ideal if it were possible to mouse press on a specific region of the screen for the circles to start falling. Any advice??

Answers

  • Post your code.

    Here's my code.

    class Dot {
      float x, y, dx, dy;
      Dot(int i){
        y = -200;
      }
      void draw(){
        x+=dx;
        y+=dy;
        fill(128,128,255);
        noStroke();
        ellipse(x,y,10,10);
      }
      void reset(){
        x = width/2;
        y = -20;
        dx = random(-.4,.4);
        dy = random(2);
      }
    }
    
    ArrayList<Dot> dots = new ArrayList();
    
    void setup(){
      size(200,600);
      for( int i = 0; i < 100; dots.add( new Dot(i++) ));
    }
    
    void draw(){
      background(0);
      for( Dot d : dots ){ d.draw(); }
    }
    
    void mousePressed(){
      for( Dot d : dots ){ d.reset(); }
    }
    
  • Look at mousePressed() in the reference and the Simple Particle System example on the website

  • thanks so much!

Sign In or Register to comment.