forked from kkwik/BoxSplitGrammars-Update
/
makePattern.py
executable file
·108 lines (82 loc) · 2.19 KB
/
makePattern.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from PIL import Image
from PNGSplitGrammar import rule, split, reorient, void, fill, start_symbol, Dimension, Direction, Constraint, clearrules, make_box, RED, GREEN, BLUE, WHITE, box
clearrules(__file__)
SPIRALWIDTH = 5
@rule
def bfill():
with split(Dimension.X, [-1,SPIRALWIDTH]):
fill(BLUE)
fill(WHITE)
@rule(constraint=Dimension.Y > 2*SPIRALWIDTH)
def bspiral():
with split(Dimension.Y, [-1, SPIRALWIDTH,SPIRALWIDTH]):
rspiral()
bfill()
fill(WHITE)
@rule(constraint=Constraint.ELSE)
def bspiral():
fill(WHITE)
@rule
def lfill():
with split(Dimension.Y, [-1,SPIRALWIDTH]):
fill(BLUE)
fill(WHITE)
@rule(constraint=Dimension.X > 2*SPIRALWIDTH)
def lspiral():
with split(Dimension.X, [SPIRALWIDTH,SPIRALWIDTH,-1]):
fill(WHITE)
lfill()
bspiral()
@rule(constraint=Constraint.ELSE)
def lspiral():
fill(WHITE)
@rule
def tfill():
with split(Dimension.X, [SPIRALWIDTH, -1]):
fill(WHITE)
fill(BLUE)
@rule(constraint=Dimension.Y > 2*SPIRALWIDTH)
def tspiral():
with split(Dimension.Y, [SPIRALWIDTH,SPIRALWIDTH,-1,]):
fill(WHITE)
tfill()
lspiral()
@rule(constraint=Constraint.ELSE)
def tspiral():
fill(WHITE)
@rule
def rfill():
with split(Dimension.Y, [SPIRALWIDTH, -1]):
fill(WHITE)
fill(BLUE)
@rule(constraint=Dimension.X > 2*SPIRALWIDTH)
def rspiral():
with split(Dimension.X, [-1,SPIRALWIDTH,SPIRALWIDTH]):
tspiral()
rfill()
fill(WHITE)
@rule(constraint=Constraint.ELSE)
def rspiral():
fill(WHITE)
def tile():
rspiral()
TILESIZE = 40
@rule()
def column():
with split(Dimension.Y, [-1,-1]):
pattern()
pattern()
@rule(constraint=Dimension.X > TILESIZE)
def pattern():
with split(Dimension.X, [-1,-1]):
column()
column()
@rule()
def pattern():
tile()
if __name__ == "__main__":
image = Image.new("RGB", (480, 480), (255,255,255))
bbox = make_box((0,0,0), (480,480,1))
sc = start_symbol(bbox, image)
pattern()
image.save("result.png")