-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursive_div.pde
More file actions
84 lines (68 loc) · 1.74 KB
/
Copy pathrecursive_div.pde
File metadata and controls
84 lines (68 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Recursive division algorithm in P3 by vvixi
float blk;
float c;
int index = 0, mid, path;
int gridSz = 100;
int[][] grid = new int[gridSz][gridSz];
void setup() {
surface.setTitle("Recursive Division");
// create initial empty grid to recursively divide on
colorMode(HSB, 300);
frameRate(120);
size(800, 800);
background(0);
stroke(200, 100, 0);
blk = width/100;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[0].length; j++) {
fill(40);
stroke(100, 200, 200, 50);
rect(i*blk, j*blk, blk, blk);
}
}
div_map(0, gridSz, gridSz, 6);
}
void draw() {
// pass
}
public void div_map(int start, int _mapW, int _mapH, int _iter) {
int mapW = _mapW;
int mapH = _mapH;
int iter = _iter;
int cullA, cullB;
boolean hori;
//if (mapW > mapH) { hori = true;
//} else if (mapH > mapW) { hori = false;
//} else {
if (random(0, mapW+mapH) < mapW) { hori = false;} else { hori = true;}
if (!hori) {
// make vert div
if (mapH/2 > 3) { mid = mapW/2; } else { return; }
cullA = int(random(mapH));
cullB = cullA - 1;
for (int i = start; i < mapH; i++) {
if (i != cullA && i != cullB) {
fill(c, c, 300);
rect(mid * blk, i * blk, blk, blk);
}
}
mapW /= 2;
iter--;
}
else if (hori) {
// make hor div
if (mapW/2 > 3) { mid = mapH/2; } else {return; }
cullA = int(random(mapW));
cullB = cullA - 1;
for (int i = start; i < mapW; i++) {
if (i != cullA && i != cullB) {
fill(c, c, 300);
rect(i * blk, mid * blk, blk, blk);
}
}
mapH /= 2;
iter--;
}
// mid to mapW, 0 to mid, call recursively on each new div
if (iter>0) {div_map(0, mapW, mapH, iter);}
}