Advertisement
Guest User

PWC20

a guest
Jul 31st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import wblut.processing.*;
  2. import wblut.geom.*;
  3. import java.util.List;
  4.  
  5. List<WB_Point> points;
  6. WB_Polygon boundary0,boundary1,boundary2,boundary3;
  7.  
  8. List<WB_VoronoiCell2D> voronoiXY0,voronoiXY1,voronoiXY2,voronoiXY3;
  9. List<WB_Mesh> columns0,columns1,columns2,columns3;
  10.  
  11.  
  12. WB_Render3D render;
  13. WB_GeometryFactory gf=WB_GeometryFactory.instance();
  14. float t=1;
  15.  
  16. void setup() {
  17.   size(800, 600, P3D);
  18.   smooth(8);
  19.  
  20.   render= new WB_Render3D(this);
  21.  
  22.   points=new ArrayList<WB_Point>();
  23.   // add points to collection
  24.   for (int i=0; i<100; i++) {
  25.     for (int j=0; j<100; j++) {
  26.       points.add(new WB_Point(-1000+i*40, -1000+j*40, 0));
  27.     }
  28.   }
  29.   createBoundaryPolygon0();
  30.   voronoiXY0= WB_Voronoi.getClippedVoronoi2D(points, boundary0, 4);
  31.   columns0=new ArrayList<WB_Mesh>();
  32.   for (WB_VoronoiCell2D vor : voronoiXY0) {
  33.     columns0.add(gf.createPrism(vor.getPolygon(),random(500,700)));
  34.   }
  35.   createBoundaryPolygon1();
  36.   voronoiXY1= WB_Voronoi.getClippedVoronoi2D(points, boundary1, 4);
  37.   columns1=new ArrayList<WB_Mesh>();
  38.   for (WB_VoronoiCell2D vor : voronoiXY1) {
  39.     columns1.add(gf.createPrism(vor.getPolygon(),random(50,500)));
  40.   }
  41.   createBoundaryPolygon2();
  42.   voronoiXY2= WB_Voronoi.getClippedVoronoi2D(points, boundary2, 4);
  43.   columns2=new ArrayList<WB_Mesh>();
  44.   for (WB_VoronoiCell2D vor : voronoiXY2) {
  45.     columns2.add(gf.createPrism(vor.getPolygon(),random(30,250)));
  46.   }
  47.   createBoundaryPolygon3();
  48.   voronoiXY3= WB_Voronoi.getClippedVoronoi2D(points, boundary3, 4);
  49.   columns3=new ArrayList<WB_Mesh>();
  50.   for (WB_VoronoiCell2D vor : voronoiXY3) {
  51.     columns3.add(gf.createPrism(vor.getPolygon(),random(10,120)));
  52.   }
  53.  
  54. }
  55.  
  56. void draw() {
  57.  
  58.   background(20);
  59.   directionalLight(255, 255, 255, 1, 1, -1);
  60.   directionalLight(127, 127, 127, 1, -1, 1);
  61.   translate(400, 400, -1000);
  62.   fill(0);
  63.   rotateY(t);
  64.   t = t+0.005;
  65.   scale(t);
  66.   rotateX(PI/2);
  67.   translate(0, 0, -200);
  68.   noFill();
  69.  
  70.   stroke(0);
  71.   strokeWeight(1);
  72.  
  73.  
  74.  /* for (WB_Mesh mesh : columns) {
  75.     render.drawMeshEdges(mesh);
  76. */
  77.  
  78.   noStroke();
  79.   fill(255);
  80.   for (WB_Mesh mesh : columns0) {
  81.     render.drawMeshFaces(mesh);
  82.   }
  83.   for (WB_Mesh mesh : columns1) {
  84.     render.drawMeshFaces(mesh);
  85.   }
  86.   for (WB_Mesh mesh : columns2) {
  87.     render.drawMeshFaces(mesh);
  88.   }
  89.   for (WB_Mesh mesh : columns3) {
  90.     render.drawMeshFaces(mesh);
  91.   }
  92.   saveFrame("frames/####.tif");
  93. }
  94.  
  95. void createBoundaryPolygon0(){
  96.   ArrayList<WB_Point> shell0;
  97.  
  98.     shell0= new ArrayList<WB_Point>();
  99.   for (int i=0; i<6; i++) {
  100.     shell0.add(gf.createPointFromPolar(50, TWO_PI/6*i));
  101.   }
  102.   //holes and points cannot overlap
  103.  
  104.  ArrayList<WB_Point> hole0=new ArrayList<WB_Point>();
  105.   for (int i=0; i<6; i++) {
  106.  hole0.add(gf.createPointFromPolar(3, TWO_PI/6*i).addSelf(0, 0, 0));
  107.   }
  108.  
  109.   boundary0=gf.createPolygonWithHole(shell0, hole0);
  110.  
  111. }
  112.  
  113. void createBoundaryPolygon1(){
  114.   ArrayList<WB_Point> shell;
  115.  
  116.     shell= new ArrayList<WB_Point>();
  117.   for (int i=0; i<6; i++) {
  118.     shell.add(gf.createPointFromPolar(200, TWO_PI/6*i));
  119.   }
  120.   //holes and points cannot overlap
  121.  
  122.  ArrayList<WB_Point> hole=new ArrayList<WB_Point>();
  123.   for (int i=0; i<6; i++) {
  124.  hole.add(gf.createPointFromPolar(50, TWO_PI/6*i).addSelf(0, 0, 0));
  125.   }
  126.  
  127.   boundary1=gf.createPolygonWithHole(shell, hole);
  128.  
  129. }
  130.  
  131. void createBoundaryPolygon2(){
  132.   ArrayList<WB_Point> shell2;
  133.  
  134.     shell2= new ArrayList<WB_Point>();
  135.   for (int i=0; i<8; i++) {
  136.     shell2.add(gf.createPointFromPolar(400, TWO_PI/8*i));
  137.   }
  138.   //holes and points cannot overlap
  139.  
  140.  ArrayList<WB_Point> hole2=new ArrayList<WB_Point>();
  141.   for (int i=0; i<6; i++) {
  142.  hole2.add(gf.createPointFromPolar(200, TWO_PI/6*i).addSelf(0, 0, 0));
  143.   }
  144.  
  145.   boundary2=gf.createPolygonWithHole(shell2, hole2);
  146.  
  147. }
  148.  
  149. void createBoundaryPolygon3(){
  150.   ArrayList<WB_Point> shell3;
  151.  
  152.     shell3= new ArrayList<WB_Point>();
  153.   for (int i=0; i<18; i++) {
  154.     shell3.add(gf.createPointFromPolar(800, TWO_PI/18*i));
  155.   }
  156.   //holes and points cannot overlap
  157.  
  158.  ArrayList<WB_Point> hole3=new ArrayList<WB_Point>();
  159.   for (int i=0; i<6; i++) {
  160.  hole3.add(gf.createPointFromPolar(400, TWO_PI/6*i).addSelf(0, 0, 0));
  161.   }
  162.  
  163.   boundary3=gf.createPolygonWithHole(shell3, hole3);
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement