Monday, June 20, 2011

grabClaw

// just type here
// and click "save" when your done



float inc = 0.0;
int numTails = 20;


Tail [] testTails = new Tail[numTails];
Tail [] badTails = new Tail[numTails];

void setup() { 
  size(800, 600); 
  stroke(255, 50);
  //smooth();

  for (int i = 0; i < testTails.length; i++) {

    testTails[i] = new Tail(100+i*2, 6+i, sin(inc)/10.0 + sin(inc*1.2)/20.0);
    badTails[i] = new Tail (200+i*4, 20+i, sin(inc)/20.0 + sin(inc*1.2)/40.0);
  }


  //testTail = new Tail(20, 10, sin(inc)/10.0 + sin(inc*1.2)/20.0);


void draw() { 
  background(0);
  inc += 0.01;
  float angle = sin(inc)/10.0 + sin(inc*1.2)/20.0;




  for (int j = 0; j < testTails.length; j++) {

    float changedAngle = angle+j;

    testTails[j].update(changedAngle/1.3);
    testTails[j].display();
    badTails[j].update(changedAngle*2);
    badTails[j].display();
    //testTails[j].update(changedAngle*2);
    //testTails[j].display();
  }


  /*
    tail(18, 9, angle/1.3);
   tail(33, 12, angle);
   tail(44, 10, angle/1.3);
   tail(62, 5, angle);
   tail(88, 7, angle*2);
   */
}

class Tail {
  float x, y;
  float angle;
  int units;

  //constructor
  Tail (float xpos, int u, float ang) {
    x=xpos;
    //y=ypos;
    angle=ang;
    units = u;
  }

  void update(float tempAngle) {
    angle=tempAngle;
  }

  void display() {

    pushMatrix();
    translate(x, 100);
    for (int i = units; i>0; i--) {
      strokeWeight(i);
      line(0, 0, 0, -30);//was -8
      //translate(0, -30);// same as above

      translate(40,-50);
      rotate(angle);
    }
    popMatrix();
  }
}

info info

submitted by: sevenspiral1
views: 1013
This is a sketch that reminds me of being on the beach with a load of angry crabs as a kid, so happy to recreate the experience with sin...

Tags:

comments comment

loading loading...

 

Add a comment: