• fullscreen
  • Empathy.pde
  • /**
    <p>Don't move too fast &mdash; you might scare it. Click to forgive and forget.</p>
    */
    
    int n = 5000; // number of cells
    float bd = 37; // base line length
    float sp = 0.004; // rotation speed step
    float sl = .97; // slow down rate
    
    Cell[] all = new Cell[n];
    
    class Cell{
      int x, y;
      float s = 0; // spin velocity
      float c = 0; // current angle
      Cell(int x, int y) {
        this.x=x;
        this.y=y;
      }
      void sense() {
        if(pmouseX != 0 || pmouseY != 0)
          s += sp * det(x, y, pmouseX, pmouseY, mouseX, mouseY) / (dist(x, y, mouseX, mouseY) + 1);
        s *= sl;
        c += s;
        float d = bd * s + .001;
        line(x, y, x + d * cos(c), y + d * sin(c));
      }
    }
    
    void setup(){
      size(300, 300, P2D);
      stroke(0, 0, 0, 20);
      for(int i = 0; i < n; i++){
        float a = i + random(0, PI / 9);
        float r = ((i / (float) n) * (width / 2) * (((n-i) / (float) n) * 3.3)) + random(-3,3) + 3;
        all[i] = new Cell(int(r*cos(a)) + (width/2), int(r*sin(a)) + (height/2));
      }
    }
    
    void draw() {
      background(255);
      for(int i = 0; i < n; i++)
        all[i].sense();
    }
    
    void mousePressed() {
      for(int i=0;i<n;i++)
        all[i].c = 0;
    }
    
    float det(int x1, int y1, int x2, int y2, int x3, int y3) {
      return (float) ((x2-x1)*(y3-y1) - (x3-x1)*(y2-y1));
    }
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement


    Kyle McDonald

    Empathy

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

    Don't move too fast, you might scare it.

    Click to forgive and forget.

    feels very alive!
    Kyle McDonald
    9 Mar 2009
    Thanks -- that is exactly what I was going for :)
    Eduardo Cavazos
    29 Apr 2009
    Yikes! Very very cool...
    sOrarize
    3 May 2009
    perfect!
    I's incredible how cool it is with these few lines of code! Congratulations!!
    Mark Brand
    22 Jun 2009
    Awesomely real. Have to look into this! Fave'd.
    Claudio Gonzales
    22 Jun 2009
    Wow... that is amazing. It feels so incredibly real. Great job!
    Sander Sturing
    24 Jun 2009
    yeah, really nice! it surpised me, looks alive indeed!
    Starkes
    24 Jun 2009
    furry, wow.
    metin saray
    17 Oct 2009
    best sketch ever
    Hello, my name is Elliot Blanchard - I'm a director and motion designer. I love your work - would you be interested in collaborating on an interactive piece?

    You can see my recent projects at http://www.royalcolornetwork.com.
    Kyle McDonald
    11 Dec 2009
    Hi Elliot, I am interested! Send me an email describing the piece you have in mind -- my email is at the top of my website: http://www.kylemcdonald.net/
    arquine wong
    7 Jan 2010
    Amazing!
    Delightful!
    tim rich
    16 Jan 2011
    a beautiful fur you have created!
    fawaz
    25 Feb 2011
    awesome piece !!!!!!
    great! it's initially really surprising and draws you in to play with it. love it!
    Ruairi Murphy
    23 Apr 2011
    love it.
    Ben G
    31 Jan 2012
    elegant, simple, beautiful.
    peoplepeople
    10 Oct 2012
    Kyle McDonald, is there a way I can contact you I really need your help
    You need to login/register to comment.