Advertisement
xeromino

iso

Oct 27th, 2014
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. float d=30;
  2. int num=300, edge=150, rs, f;
  3.  
  4. void setup() {
  5.   colorMode(HSB, 360, 100, 100);
  6.   size(1000, 800);
  7.   background(#202020);
  8. }
  9.  
  10. void draw() {
  11. }
  12.  
  13. void mouseClicked() {
  14.   background(20);
  15.   f = (int) random(360);
  16.   rs = (int) random(10000);
  17.   for (int i=0; i<num; i++) {
  18.     drawIsoCube();
  19.   }
  20. }
  21.  
  22. void keyPressed() {
  23.   saveFrame("image-###.gif");
  24. }
  25.  
  26. void drawIsoCube() {
  27.   //f = (int) random(360);
  28.   int orgX, orgY;
  29.   int[] x = new int[7];
  30.   int[] y = new int[7];
  31.   int w = int(cos(radians(30))*d);
  32.   int h = int(sin(radians(30))*d);
  33.   int rx = (int) random(width/d);
  34.   int ry = (int) random(height/d);
  35.   if (random(1)>.5) {
  36.     orgX=rx*w*2;
  37.     orgY=ry*h*2;
  38.   } else {
  39.     orgX=w+rx*w*2;
  40.     orgY=(ry*h*2)+h;
  41.   }
  42.   if (orgX<edge || orgX>width-edge || orgY<edge || orgY>height-edge) {
  43.   } else {
  44.     x[0]=orgX;
  45.     y[0]=orgY;
  46.     x[1]= x[0];
  47.     y[1]= int(y[0]+d);
  48.     x[2]= int(x[1]-w);
  49.     y[2]= int(y[1]-h);
  50.     x[3]= x[2];
  51.     y[3]= int(y[2]-d);
  52.     x[4]= x[0];
  53.     y[4]= int(y[0]-d);
  54.     x[5]= int(x[0]+w);
  55.     y[5]= int(y[0]-h);
  56.     x[6]= x[5];
  57.     y[6]= int(y[5]+d);
  58.     stroke(#202020);
  59.     noStroke();
  60.     fill(f, 90, 60);
  61.     quad(x[0], y[0], x[1], y[1], x[2], y[2], x[3], y[3]);
  62.     fill(f, 90, 90);
  63.     quad(x[0], y[0], x[3], y[3], x[4], y[4], x[5], y[5]);
  64.     fill(f, 90, 40);
  65.     quad(x[0], y[0], x[5], y[5], x[6], y[6], x[1], y[1]);
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement