Thursday, January 22, 2009

Assignment 3 Bezier Curves



a

void setup()
{
  size(200,600);
  background(0);
  stroke(255);
}

void draw()
{
  LinCurv(15,150,75,15);
  LinCurv(50,120,120,160);
  LinCurv(130,130,170,25);
  QuadCurv(50,370,80,210,110,270);
  QuadCurv(90,380,140,290,190,390);
  CubicCurv(50,570,40,500,100,490,150,580);
  CubicCurv(120,500,110,410,170,420,190,510);
}

void LinCurv(int x0, int y0, int x1, int y1)
{
  for(float t=0; t <>
  {
    float x,y;
    
    x = x0 *(1-t)+ t * x1;
    y = y0 *(1-t)+ t*y1;
    point(x, y);
  }
}

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

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