• fullscreen
  • Sable.pde
  • TP_2Carl.pde
  • class Sable {
      float x,y,v,r;
    
      Sable(float x_, float y_, float r_){
        x = x_;
        y = y_;
        v = 17;
        r = r_;
      }
    
      void update(){
    
    
        float distance = dist(mouseX,mouseY,x,y);
    
        if (distance < 14 ){
          if (mousePressed){
            float radians = atan2(mouseY-y,mouseX-x)+PI;
            x = x + v * cos(radians);
            y = y + v * sin(radians);
          }
        }
    
        x = constrain (x,r/2,width-r/2);
        y = constrain(y,r/2,height-r/2);
    
        noStroke();
        fill(242,238,110);
        ellipse(x,y,r,r);
      }
    
    
    }
    
    
    
    
    
    
    Sable sable;
    ArrayList sables;
    
    void setup() {
      size(256,256);
      sables = new ArrayList();
      for (int i = 0; i < 10000; i++) {
    
        sables.add(new Sable (random(width),random(height),0.5));
    
      }
    
    }
    
    void draw() {
      background (162,158,26);
      for ( int i = 0 ; i < sables.size(); i ++){
        Sable sable = (Sable) sables.get(i);
        sable.update();
    
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Carl Beaumier

    Sand Painting

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

    Hey hi again !

    This is a little something to paint. it is like if you're painting into the sand ! Hold the mouse button to draw.

    If someone know how I should implement a code to restart the skecth when the user press a key, plz answer me ! THX

    Carl

    dotlassie
    21 Feb 2010
    Hi, i didn't tried it, but it might work:

    void keyPressed() { setup(); }
    Carl Beaumier
    22 Feb 2010
    No, it doesn't. Or...whereshould I put it in the code. thx
    polar
    21 Mar 2010
    put it after the whole draw-thing - at the end of your sketch. May need some refinement though.

    You need to login/register to comment.