Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. void setup () {
  2. noLoop();
  3. size (500, 500);
  4. }
  5. void mondrian (int x0, int y0, int x1, int y1, int level) {
  6. int d = int(random(x0, x1));
  7. int f = int(random (y0, y1 ));
  8.  
  9. if (level == 0) {
  10. return;
  11. } else {
  12.  
  13. rectMode (CORNERS);
  14.  
  15. fill( random (0, 255), random (0, 255), random (0, 255));
  16. rect (x0, y0, d, f);
  17.  
  18. fill( random (0, 255), random (0, 255), random (0, 255));
  19. rect (d, y0, x1, f);
  20.  
  21. fill( random (0, 255), random (0, 255), random (0, 255));
  22. rect (x0, f, d, y1);
  23.  
  24. fill( random (0, 255), random (0, 255), random (0, 255));
  25. rect (d, f, x1, y1);
  26.  
  27. mondrian(x0, y0, d, f, level-1);//topleft rectangle
  28. mondrian(d, y0, x1, f, level-1);//topright rectangle
  29. mondrian(x0, f, d, y1, level-1);//bottomleft rectangle
  30. mondrian (d, f, x1, y1, level-1);//bottomright rectangle
  31. }
  32. }
  33.  
  34. void draw () {
  35.  
  36. int level=3; // number of times the mondrian will recur
  37. int x0 = 0;
  38. int y0 = 0;
  39. int x1 = width;
  40. int y1 = height;
  41.  
  42. mondrian(x0, y0, x1, y1, level);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement