Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. //int x0
  2. //int y0
  3. // int x1
  4. // int y1
  5. // int i
  6. // int j
  7. // (x0, y0) = top left corner
  8. // (x1, y0) = top right corner
  9. // (x0, y1) = bottom left corner
  10. // (x1, y1) = bottom right corner
  11. // (i, j) = intersection creating first four rerctangles
  12. //void mondrian (int x1, int y1, int x2, int y2, int level);
  13. //rmondrian (x0, y0, i, j, level +1 );
  14. //rmondrian (x1, y0, i, j, level +1);
  15. //rmondrian (x0, y1, i, j, level +1);
  16. //rmondrian (x1, y1, i, j, level +1);
  17.  
  18. void setup() {
  19. size(400, 400);
  20. rmondrian(0, 0, 400, 400, 0);
  21. }
  22.  
  23. void rmondrian(int x0, int y0, int x1, int y1, int level ) {
  24. int i= int(random(x0, x1));
  25. int j = int(random(y0, y1));
  26. if (level == 2) {
  27. return;
  28. } else {
  29. line(i, y0, i, y1);
  30. line(x0, j, x1, j);
  31. fill(random(0, 255), random(0, 255), random(0, 255));
  32. rect(x0, y0, i, j);
  33. fill(random(0, 255), random(0, 255), random(0, 255));
  34. rect(i, y0, x1, j);
  35. fill(random(0, 255), random(0, 255), random(0, 255));
  36. rect(x0, j, i, y1);
  37. fill(random(0, 255), random(0, 255), random(0, 255));
  38. rect(i, j, x1, y1);
  39.  
  40. level=level+1;
  41. rmondrian (x0, y0, i, j, level);
  42. rmondrian (i, y0, x1, j, level);
  43. rmondrian (x0, j, i, y1, level);
  44. rmondrian (i, j, x1, y1, level );
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement