Sunday, February 1, 2009

Cubic Click



int x0, y0, x1, y1, x2, y2, x3, y3;
int count = 0;
void setup()
{
  size(400,400);
}
void draw()
{
}

void mousePressed()
  if (count == 0)
  {
    x0 = mouseX;
    y0 = mouseY;
    point(x0, y0);
    count++;
  }
  else if (count == 1)
  {
    x1= mouseX;
    y1 = mouseY;
    count++;
  }
  else if (count == 2)
  {
    x2 = mouseX;
    y2 = mouseY;
    count++;
  }
  else
  {
    x3 = mouseX;
    y3 = mouseY;
    CubicCurv(x0, y0, x1, y1, x2, y2, x3, y3);
    count = 0;
  }
}

void CubicCurv(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
{
  float x, y;
  for(float t = 0 ; t <>
  {
    x= (1-t)*(1-t)*(1-t)*x0 + 3 *(1-t)*(1-t)*t*x1+ 3*(1-t)*(1-t)*t*t*x2 + t*t*t*x3;
    y= (1-t)*(1-t)*(1-t)*y0 + 3 *(1-t)*(1-t)*t*y1+ 3*(1-t)*(1-t)*t*t*y2 + t*t*t*y3;
    point(x,y);
  }
}

No comments:

Post a Comment