• fullscreen
  • Drop.pde
  • rain.pde
  • class Drop{
      int x,y,d,z,onde,d1,oldY;
      float acc;
      boolean s;
    
      Drop(int x,int y, int z, int d){ // x start, y start, y end ,width of ellipse
        this.x=x;
        this.y=y;
        this.d=d;
        this.z=z;
        onde=0;
        d1=d;
        acc=0;
        oldY=y;
        s=true;
      }
    
      void fall(){
        if(y>0)acc+=0.1;
        stroke(255,255,255,map(z,0,height,0,255));
        strokeWeight(2);
        if (y<z){
          y=int(y+2+acc);
          line(x,oldY,x,y);
          s=true;
          oldY=y;
        }
        else{
          noFill();
          stroke(255,255,255,255-map(onde,0,d,0,255));
          strokeWeight(map(onde,0,d,0,4));
          if(s==true){
            ch++;
            ch=ch%9;
            sc.channel(ch);
            sc.pan(int(map(x,0,width,left,right))); 
            sc.instrument(instr);
            sc.playNote(map(x,0,width,pitch,pitch+32), map(y,0,height,0,127), 0.2);
          }
          s=false;
          d=d1+(y-height)*4;
          ellipse(x,y,onde/5,onde/20);
          onde=onde+8;
          if(onde>d){
            onde=0;
            acc=0;
            x=int(random(width));
            y=-int(random(height*2));
            oldY=y;
            d=d1;
          }
        }
      }
    }
    
    
    
    import arb.soundcipher.*;
    import arb.soundcipher.constants.*;
    
    SoundCipher sc = new SoundCipher(this);
    PFont font12;
    
    int nb=50; // number of drops
    int maxDrops =150;
    int minDrops=5;
    int h,h1;
    int instr=4, pitch=50;
    int ch=0;  
    boolean show=true;
    int left=0,right=127, prov;
    
    Drop[] drops=new Drop[maxDrops];
    
    void setup(){
      size(768,400,P3D);
      smooth();
      frameRate(30);
      h = abs(height/3);
      h1=h*2;
      sc.instrument(instr);
      font12=loadFont("rain-12.vlw");
      textFont(font12,12);
      textMode(SCREEN);
      for (int i = 0; i < maxDrops; i++){
        drops[i] = new Drop(int(random(width)),-int(random(height*2)),h+int(random(h1)),1280); 
      }
    }
    
    void draw(){
      gradient();
      for (int i=0;i<nb;i++){
        drops[i].fall();
      }
      if (show==true){
      fill(255);
      text ("KEYS = 0..9: Midi sound presets("+instr+") | q/w : inc/dec pitch ("+ pitch+"-"+(pitch+32)+") | +/- : inc/dec raindrops ("+nb+") | s: swap stereo channels | h: show/hide this",5,15);
      }
    }
    
    void gradient(){
      noStroke();
      beginShape(QUADS);
      fill(188,190,192); 
      vertex(0,0); 
      vertex(width,0);
      fill(0,0,0); 
      vertex(width,height); 
      vertex(0,height);
      endShape(); 
    }
    
    
    void keyPressed() {
      switch (key){
      case '+':
        if(nb<maxDrops){
          nb++;
        }
        break;
      case '-':
        if(nb>minDrops){
          nb--;
        }
        break;
      case 'q':
        if(pitch<95){
          pitch++;
        }
        break;
      case 'w':
        if(pitch>1){
          pitch--;
        }
        break;
      case '0':
          instr=4;
      break;
      case '1':
          instr=102;
      break;
      case '2':
          instr=108;
      break;
      case '3':
          instr=115;
      break;
      case '4':
         instr=116;
      break;
      case '5':
          instr=12;
      break;
      case '6':
          instr=46;
      break;
      case '7':
          instr=53;
      break;
      case '8':
          instr=88;
      break;
      case '9':
          instr=9;
      break;
      case 'h':
          if (show==true){show=false;}else{show=true;}
      break;
      case 's':
          prov=left;left=right ;right=prov;
      break;
      }
    }
    
    
    
    
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Maxime Gaillard

    RainDrops

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

    Raindrops keep fallin' on my head
    And just like the guy whose feet are too big for his bed
    Nothin' seems to fit
    Those raindrops are fallin' on my head, they keep fallin'
    (credit to B.J. Thomas lyrics)

    Guigui plus+
    27 Aug 2009
    8^D …… Nicely done in all points!
    Maxime Gaillard
    28 Aug 2009
    Merci beaucoup !
    Jean Gilbert
    2 Mar 2013
    Hi Maxime,
    thank you for the source, I use it for AV performances and added the kinect body motion control.
    Welcome on http://www.jean-gilbert.com
    credits are also there.

    Regards,
    Jean Gilbert
    I'm glad that you found it usefull !
    Jean Gilbert
    24 Mar 2013
    Thank you, Maxime, I will also copy your answer to the guestbook, ok?
    Best Regards,
    gil
    You need to login/register to comment.