Saturday, August 22, 2009

dorkbot09v5

// just type here
// and click "submit" when done

// ms it will take snap back
int snapTime = 300;

// time we start snapping
int startSnapTime;

// last rotation position
float lastRotate = 0.0;

int pmouseX = 0;


void setup(){
  size (300,300);
  startSnapTime = millis();
  pmouseX = mouseX;
  strokeWeight(10.0);
  strokeJoin(BEVEL);
  stroke(153);
}
  
void draw()
{
  background(20,30,40);
  fill(190,90,90);

  int dmouse = mouseX - pmouseX;

  pmouseX = mouseX;


  if (abs(dmouse) > 0)
  {
    // reset start snap time
    startSnapTime = millis();

    lastRotate = map(mouseX, 0, width, 0.0, TWO_PI);
    
    pushMatrix();
    translate(width/2, height/2);
    rotate(lastRotate);
    ellipse(0,0,100+mouseX/4,100);
    popMatrix();
  }
  else
  {
     float timeDiff = millis() - startSnapTime;
     if (timeDiff > snapTime) timeDiff = snapTime;
     pushMatrix();
      translate(width/2, height/2);
      rotate((float)timeDiff/(float)snapTime *lastRotate);
    ellipse(0,0,100+mouseX/4,100);
    popMatrix();
  }
}

info info

submitted by: mars
views: 



treeThis sketch has a parent
Tags: dorkbot

comments comment

loading loading...

 

Add a comment: