Guest User

Untitled

a guest
Dec 11th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. int[] xAnchors = new int[4];
  2. int[] yAnchors = new int[4];
  3.  
  4. int columns = 12;
  5. int rows = 8;
  6.  
  7. int columnWidth;
  8. int rowHeight;
  9.  
  10. int frameSize = 40;
  11.  
  12. ArrayList shapes = new ArrayList();
  13.  
  14.  
  15. void setup(){
  16. size(900, 600, P3D);
  17.  
  18. columnWidth = (width - frameSize)/columns;
  19. rowHeight = (height - frameSize)/rows;
  20.  
  21. generate();
  22. }
  23.  
  24. void generate(){
  25. shapes.clear();
  26. for(int c = 0 ; c < columns ; c++){
  27. for(int r = 0 ; r < rows ; r++){
  28. shapes.add(makeShape());
  29. }
  30. }
  31. }
  32.  
  33. PShape makeShape(){
  34.  
  35. xAnchors[0] = (int)random(columnWidth/2);
  36. xAnchors[1] = (int)random(columnWidth/2) + columnWidth/2;
  37. xAnchors[2] = (int)random(columnWidth/2) + columnWidth/2;
  38. xAnchors[3] = (int)random(columnWidth/2);
  39.  
  40. yAnchors[0] = rowHeight/2 + (int) random(rowHeight/8, -(rowHeight/8));
  41. yAnchors[1] = (int)random(rowHeight/2);
  42. yAnchors[2] = rowHeight/2 + (int) random(rowHeight/8, -(rowHeight/8));
  43. yAnchors[3] = (int)random(rowHeight/2) + rowHeight/2;
  44.  
  45. PShape shape = createShape();
  46. shape.beginShape();
  47.  
  48. shape.stroke(50);
  49. shape.noFill();
  50. shape.vertex(xAnchors[0], yAnchors[0]);
  51. shape.bezierVertex(xAnchors[0], yAnchors[0], xAnchors[1], yAnchors[1], xAnchors[2], yAnchors[2]);
  52. shape.stroke(100);
  53. shape.bezierVertex(xAnchors[2], yAnchors[2], xAnchors[3], yAnchors[3], xAnchors[0], yAnchors[0]);
  54.  
  55. shape.endShape();
  56. return shape;
  57. }
  58.  
  59. void draw(){
  60. background(#e0ded5);
  61.  
  62. int index = 0;
  63. for(int c = 0 ; c < columns ; c++){
  64. for(int r = 0 ; r < rows ; r++){
  65. PShape aShape = (PShape)shapes.get(index);
  66. shape(aShape, frameSize/2 + columnWidth * c , frameSize/2 + rowHeight * r);
  67. index++;
  68. }
  69. }
  70.  
  71. noLoop();
  72. }
  73.  
  74. void mousePressed(){
  75. generate();
  76. loop();
  77. }
Add Comment
Please, Sign In to add comment