• fullscreen
  • Rain.pde
  • raintest.pde
  • public class Rain
    {
      PVector position,pposition,speed;
      float col;
      
      public Rain()
      {
        position = new PVector(random(0,width),0);
        pposition = position;
        speed = new PVector(0,0);
        col = random(30,100);
      }
      
      void draw()
      {
        stroke(100,col);
        strokeWeight(2);
        line(position.x,position.y,pposition.x,pposition.y);
        //ellipse(position.x,position.y,5,5);
      }
      
      void calculate()
      {
        pposition = new PVector(position.x,position.y);
        gravity();
    
      }
      
      void gravity()
      {
        speed.y += .2;
        speed.x += .01;
        position.add(speed);
      }
    }
    
    public class Splash
    {
      PVector position,speed;
      
      public Splash(float x,float y)
      {
        float angle = random(PI,TWO_PI);
        float distance = random(1,5);
        float xx = cos(angle)*distance;
        float yy = sin(angle)*distance;
        position = new PVector(x,y);
        speed = new PVector(xx,yy);
        
      }
      
      public void draw()
      {
        strokeWeight(1);
        stroke(100,50);
        fill(100,100);
        ellipse(position.x,position.y,2,2);
      }
      
      void calculate()
      {
        gravity();
         
        speed.x*=0.98;
        speed.y*=0.98;
               
        position.add(speed);
      }
      
      void gravity()
      {
        speed.y+=.2;
      }
      
    }
    
    import processing.opengl.*;
    
    int rainNum = 100;
    ArrayList rain = new ArrayList();
    ArrayList splash = new ArrayList();
    float current;
    float reseed = random(0,.2);
    
    void setup()
    {
      size(600,600,P3D);
      colorMode(HSB,100);
      background(0);
    
      rain.add(new Rain());
      current = millis();
    }
    
    void draw()
    {
      blur(50);
      
      if ((millis()-current)/1000>reseed&&rain.size()<150)
      {
        rain.add(new Rain());
        float reseed = random(0,.2);
        current = millis();
      }
      
      for (int i=0 ; i<rain.size() ; i++)
      {
        Rain rainT = (Rain) rain.get(i);
        rainT.calculate();
        rainT.draw();
        if (rainT.position.y>height)
        {
          
          for (int k = 0 ; k<random(5,10) ; k++)
          {
            splash.add(new Splash(rainT.position.x,height));
          }
          
          rain.remove(i);
          float rand = random(0,100);
          if (rand>10&&rain.size()<150)
          rain.add(new Rain());
        }
      }
      
      for (int i=0 ; i<splash.size() ; i++)
      {
        Splash spl = (Splash) splash.get(i);
        spl.calculate();
        spl.draw();
        if (spl.position.y>height)
        splash.remove(i);
      }
    
    }
    
    void blur(float trans)
    {
      noStroke();
      fill(0,trans);
      rect(0,0,width,height);
    }
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Anastasis Chasandras
    This is great! Would love to use it in an upcoming animation that a friend and I might work on.
    Feel free to use and expand the code as you wish. Good luck with your animation project
    very nice
    Kalia
    10 May 2010
    You are genius babe .Whatever you touch gets in good structures
    Zhu Pengfei
    3 Oct 2012
    fantastic!!
    very nice work, anastasis. thanks for sharing!
    I have a question, because I am a quite beginner:
    I try to implement the code in resolume avenue through syphon server and getting this error:
    "Exception in thread "Animation Thread" java.lang.ClassCastException: processing.core.PGraphics3D cannot be cast to processing.opengl.PGraphicsOpenGL".

    do you have any experience? or do you have an idea how to fix this problem?

    thanks and cheers,
    valentina
    You need to login/register to comment.