topical media & game development

talk show tell print

graphic-processing-algorithm-Ch02-p56-p56.pde / pde



  float [] px = {
    10.,10.,40.,80.};
  float [] py = {
    10.,40.,60.,20.};
  void draw(){
    background(255);
    for(float t=0.; t<1.; t+=0.01){
      float x = px[0]*pow((1 - t),3) + 3*px[1]*t*pow((1 - t),2) + 3*px[2]*pow(t,2)*(1 - t) + px[3]*pow(t,3);
      float y = py[0]*pow((1 - t),3) + 3*py[1]*t*pow((1 - t),2) + 3*py[2]*pow(t,2)*(1 - t) + py[3]*pow(t,3);
      point(x,y);
    }
    for(int i=0; i<4; i++)
      rect(px[i],py[i],5,5);
  }
  void mouseDragged(){
    for(int i=0; i<4; i++)
      if(dist(mouseX,mouseY,px[i],py[i])<20){
        px[i] += (mouseX-pmouseX);
        py[i] += (mouseY-pmouseY);
      }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.