• fullscreen
  • Ma_Kenny_EmergentBehavior.pde
  • //Hold mouse button to gather ellipses.
    
    Bird []a;
    
    void setup()
    {
      size(600, 600);
      smooth();
      fill(100);
    
    
      a = new Bird[100];
      for (int i=0; i<a.length; i++)
      {
        a[i] = new Bird();
        a[i].x = mouseX;
        a[i].y = mouseY;
        a[i].d = (int)random(5, 10);
        a[i].v = (int)random(20, 40);
        a[i].c = color(150, 50, 100, 200);
      }
    }
    
    void draw()
    {
      background(0);
      fill(150, 0, 0);
      stroke(100);
    
      for (int i=0; i<a.length; i++)
      {
        a[i].move();
        a[i].show();
      }
    
      for (int i=0; i<a.length; i++)
      {
        if (mousePressed)
        {
          a[i].x = mouseX + random(-40, 50);
          a[i].y = mouseY + random(-40, 50);
        }
      }
    }
    class Bird
    {
      float x, y;
      int d;
      int v;
      color c;
    
      void show()
      {
        fill(c);
        ellipse(x, y, d, d);
        if (x>600) x = 0;
        if (x<0) x = 600;
        if (y>600) y = 0;
        if (y<0) y = 600;
      }
    
      void move()
      {
        x += (random(-2, 2)) * 0.1 * v;
        y += (random(-2, 2)) * 0.1 * v;
        /*x += (mouseX - width/2) * 0.1 * v;
        y += (mouseY - width/2) * 0.1 * v;*/
        
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    KenM

    Emergent Behavior

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

    Click or hold mouse button to group together.

    You need to login/register to comment.