Processsing Snippet

March 17th, 2010
JAVA:
  1. import processing.pdf.*;
  2.  
  3. int pointNum = 14;
  4. Point[] points = new Point[pointNum];
  5. void setup(){
  6.   size(500,500, JAVA2D)
  7.   beginRecord(PDF, "shape.pdf");
  8.   translate(width / 2, height / 2);
  9.   background(255);
  10.   strokeWeight(0.5);
  11.   smooth();
  12.   noFill();
  13.   addPoints();
  14.   connectPoints();
  15.   endRecord();
  16. }
  17.  
  18. void addPoints(){
  19.   float step = TWO_PI / pointNum;
  20.   float theta = step / 2;
  21.   float radius = 200;
  22.   for (int i = 0; i<pointNum; i++){
  23.      float x = radius * cos(theta);
  24.      float y = radius * sin(theta);
  25.      points[i] = new Point(x, y);
  26.      theta += step;
  27.   }
  28. }
  29. void connectPoints(){
  30.    for (int i = 0; i<pointNum; i++){
  31.      Point a = points[i];
  32.      for (int j = 0; j<pointNum; j++){
  33.         Point b = points[j];
  34.         if (a != b){
  35.            //if (int(a.x) == int(b.x) || int(a.y) == int(b.y)){
  36.              line(a.x, a.y, b.x, b.y);
  37.           // }
  38.         }
  39.      }
  40.    }
  41. }
  42.  
  43. class Point{
  44.   float x;
  45.   float y;
  46.   Point(float x, float y){
  47.     this.x = x;
  48.     this.y = y;
  49.    // ellipse(x,y, 10, 10);
  50.   }
  51. }

Connect the dots, try changing pointNum.

Actually have a good deal more to say about this snippet... maybe in the next day or two.

Leave a Reply