-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRandomMondrian.m
More file actions
70 lines (59 loc) · 1.5 KB
/
Copy pathRandomMondrian.m
File metadata and controls
70 lines (59 loc) · 1.5 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
(* ::Package:: *)
(* ::Section:: *)
(*Definition*)
(* ::Subsubsection:: *)
(*Wrap Function*)
Options[RandomMondrian] = {
AspectRatio -> 0.618,
ImageSize -> Large,
EdgeThickness -> Thickness[1 / 150],
EdgeColor -> Black,
MaxIterations -> 7,
"ColorMap" -> Automatic,
"Grids" -> 20
};
RandomMondrian[o : OptionsPattern[]] := Block[
{c, w, splitted},
{c, w} = Transpose@If[
SameQ[OptionValue["ColorMap"], Automatic],
$DefaultColorMap,
OptionValue["ColorMap"]
];
splitted = Nest[split, #, OptionValue[MaxIterations]]&@Graphics[
{
EdgeForm@OptionValue[{EdgeThickness, EdgeColor}],
Rectangle[N@{0, 0}, N@{1, OptionValue[AspectRatio]}]
},
ImageSize -> OptionValue[ImageSize]
];
splitted
/. r_Rectangle :> {RandomChoice[w -> c], r}
/. x_Real :> Round[x, 1 / Round[OptionValue["Grids"]]]
];
(* ::Subsubsection:: *)
(*Main Function*)
$DefaultColorMap = {
{RGBColor["#000000"], 1}(*Black*),
{RGBColor["#878787"], 1}(*Gray*),
{RGBColor["#194F9A"], 4}(*Blue*),
{RGBColor["#BC0118"], 4}(*Red*),
{RGBColor["#FACA02"], 4}(*Yellow*),
{RGBColor["#FDFDFD"], 16}(*White*)
};
split = # /. d : Rectangle[{x1_, y1_}, {x2_, y2_}] :> With[
{t = RandomReal@BetaDistribution[10, 10], r = RandomReal[]},
Which[
r < 0.3(x2 - x1) / (y2 - y1),
{
Rectangle[{x1, y1}, {x1 + (x2 - x1) t, y2}],
Rectangle[{x1 + (x2 - x1) t, y1}, {x2, y2}]
},
1 - r < 0.5 (y2 - y1) / (x2 - x1),
{
Rectangle[{x1, y1}, {x2, y1 + (y2 - y1) t}],
Rectangle[{x1, y1 + (y2 - y1) t}, {x2, y2}]
},
True,
d
]
]&;