Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup () {
- noLoop();
- size (500, 500);
- }
- void mondrian (int x0, int y0, int x1, int y1, int level) {
- int d = int(random(x0, x1));
- int f = int(random (y0, y1 ));
- if (level == 0) {
- return;
- } else {
- rectMode (CORNERS);
- fill( random (0, 255), random (0, 255), random (0, 255));
- rect (x0, y0, d, f);
- fill( random (0, 255), random (0, 255), random (0, 255));
- rect (d, y0, x1, f);
- fill( random (0, 255), random (0, 255), random (0, 255));
- rect (x0, f, d, y1);
- fill( random (0, 255), random (0, 255), random (0, 255));
- rect (d, f, x1, y1);
- mondrian(x0, y0, d, f, level-1);//topleft rectangle
- mondrian(d, y0, x1, f, level-1);//topright rectangle
- mondrian(x0, f, d, y1, level-1);//bottomleft rectangle
- mondrian (d, f, x1, y1, level-1);//bottomright rectangle
- }
- }
- void draw () {
- int level=3; // number of times the mondrian will recur
- int x0 = 0;
- int y0 = 0;
- int x1 = width;
- int y1 = height;
- mondrian(x0, y0, x1, y1, level);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement