Advertisement
Guest User

Untitled

a guest
Oct 8th, 2012
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. public class Nagon {
  2.   float x[];
  3.   float y[];
  4.   int n;
  5.  
  6.   Nagon(int numberOfVertex, float xPos, float yPos, float rad, float theta) {
  7.     n = numberOfVertex;
  8.     x = new float[n];
  9.     y = new float[n];
  10.     int step = n - 1;
  11.     if (n % 2 == 0) step = 2;
  12.     for(int i = 0; i < n; i++){
  13.       x[i] = xPos + rad * cos( theta + (i * step * PI) / n );  
  14.       y[i] = yPos + rad * sin( theta + (i * step * PI) / n );  
  15.     }
  16.   }
  17.  
  18.   void DrawNagon () {
  19.     for (int i = 0; i < n; i++){
  20.       if (n % 2 != 0){
  21.        line(x[i],y[i],x[(i+2)%n],y[(i+2)%n]);
  22.       } else {
  23.         line(x[i],y[i],x[(i+1)%n],y[(i+1)%n]);
  24.       }
  25.     }  
  26.   }
  27. }
  28.  
  29. void setup () {
  30.   size (1000, 1600);
  31.   background (0);
  32.   stroke(255);
  33.   smooth();
  34.   for(int i = 0; i < 7; i++){
  35.     for(int j = 0; j < 4; j++){
  36.       for(int k = 1; k < 20; k++){
  37.         Nagon n = new Nagon(i+3,200 + 200*j, 200 + 200*i,k*5 ,k*j*2/PI);
  38.         n.DrawNagon();
  39.       }
  40.     }
  41.   }
  42.   noLoop();
  43.  
  44. }
  45.  
  46. //this function ripped from code written by http://markusbenjamin.tumblr.com/ who has a cool blog which you should check out
  47. void keyPressed() {
  48.   if (key=='s') {
  49.     save(nf(random(1)*1000, 4, 4)+".png");
  50.   }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement