topical media & game development

talk show tell print

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



  int n = 5;
  float[] xArray = new float[n]; //allocate memory for 5 points
  float[] yArray = new float[n];
  void setup(){
    float angle = 2 * PI / n; //divide the circle in n sections
    for(int i =0; i< n; i++){ //create points along a circle
      xArray[i] = 50. + 30. * sin(angle*i);
      yArray[i] = 50. + 30. * cos(angle*i);
    }
  }
  void draw (){
    beginShape(POLYGON);
    for(int i = 0; i < n; i++)
      vertex(xArray[i],yArray[i]);
    endShape(CLOSE);
  }
  


(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.