forked from mccutchen/funcgeo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquarelimitdemo3.py
More file actions
218 lines (178 loc) · 5.52 KB
/
squarelimitdemo3.py
File metadata and controls
218 lines (178 loc) · 5.52 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
from funcgeo import *
from fishmodel import fish
# the start symbol
start = ('u','c','b','r')
# all the substitutions needed for expanding the squarelimit quarters
shrinking_sq_rules = {
#
# these are the rules for the expanding squarelimit
#
# the idea is to construct a quarter of the picture which will be cycled() for
# the final picture.
#
#
# ucbr is the start symbol; will be expanded once
#
# u = up (upper left)
# u -> e,e,u1,u2
# u1 = up lower left expansion
# u2 = up lower right expansion
#
# c = corner (upper right)
# c -> e,e,c1,e
# c1 = corner lower left expansion
#
# b1 = base (lower left)
# base gets never expanded
#
# r = right (lower right)
# r -> r1,e,r2,e
# r1 = right upper right expansion
# r2 = right lower right expansion
#
# e = empty
# 3 parts get expanded, 1 stays constant
start: ( ('e','e','u1','u2'),
('e','e','c1','e'),
'b1',
('r1','e','r2','e') ),
('e','e','u1','u2'): ( ('e','e','u1','u2'),
('e','e','u1','u2'),
'u1',
'u2' ),
('r1','e','r2','e'): ( 'r1',
('r1','e','r2','e'),
'r2',
('r1','e','r2','e') ),
('e','e','c1','e'): ( ('e','e','u1','u2'),
('e','e','c1','e'),
'c1',
('r1','e','r2','e')),
}
growing_sq_rules = {
# 1 part gets expanded, 3 stay constant
start: ('u1',
'b1',
('u1', 'b1', 'e', 'u1'),
'u1'),
('u1','b1','e','u1'): ('u1',
'b1',
('u1', 'b1', 'e', 'u1'),
'u1'),
}
def makeparts_shrinking_squarelimit( basepict ):
"""Make the squarelimit parts; lots of vars packed up in a dict."""
picture = basepict
# two pictures filling a triangle
pictriangle = over( flip( rot45(picture)),
flip( rot( rot45(picture))))
e = blank()
b = over(picture, pictriangle)
u1 = rot(b)
u2 = b
u = quartet(e,e,u1,u2)
c1 = over(pictriangle, rot(rot(pictriangle)))
c = quartet(e,e,c1,e)
r1 = b
r2 = rot(rot(rot(b)))
r = quartet(r1,e,r2,e)
result = {
'e': blank(),
'b': b,
'b1': b,
'u': u,
'u1': u1,
'u2': u2,
'c': c,
'c1': c1,
'r': r,
'r1': r1,
'r2': r2
}
return result
def makeparts_growing_squarelimit( basepict ):
"""Make the squarelimit parts; lots of vars packed up in a dict."""
picture = basepict
# two pictures filling a triangle
pictriangle = over( flip( rot45(picture)),
flip( rot( rot45(picture))))
result = {
'e': blank(),
'b': rot(over(picture, rot(rot(picture)))),
'b1': rot(over(picture, rot(rot(picture)))),
'u': rot(rot(over(picture, pictriangle))),
'u1': rot(rot(over(picture, pictriangle)))
}
return result
def substitute( item, rules ):
"""Run one symbol (char or tuple) through expansion for one level."""
if item in rules:
return rules[item]
else:
if type(item) in (list, tuple):
result = []
for i in item:
result.append( substitute(i, rules) )
return tuple( result )
else:
return item
def makelayout( start, level, rules ):
"""Expand all symbols."""
symbols = start[:]
while True:
symbols = substitute(symbols, rules)
level -= 1
if level < 1:
break
return symbols
def makecalls( s, translator ):
"""Translate symbols to quartet calls"""
args = []
# convert strings to calls
for i in s:
if type(i) in (tuple, list):
args.append( makecalls(i, translator) )
elif type(i) in (str,):
args.append( translator[i] )
else:
print "Should not happen."
pdb.set_trace()
print s
print i
print args
if len(args) != 4:
pdb.set_trace()
result = []
# a final clean up (because it's not clean...
for i in args:
try:
item = result.append( translator[i] )
except KeyError, err:
item = i
result.append(i)
r = ()
# debugging remnant
try:
r = quartet( *result )
except TypeError, err:
pdb.set_trace()
print err
print result
return r
if __name__ == '__main__':
# make lots of squarelimit pictures
layout_shrinking = layout_growing = start
for i in range(3):
# 2 layouts
layout_shrinking = makelayout( layout_shrinking, i, shrinking_sq_rules)
layout_growing = makelayout( layout_growing, i, growing_sq_rules)
# 1 pictures * 2 layouts
# fish
fish_shrinking = makeparts_shrinking_squarelimit( fish )
fish_growing = makeparts_growing_squarelimit( fish )
# 4 quarters each in a shrinking and a growing style
fishquarters_s = makecalls(layout_shrinking, fish_shrinking)
fishquarters_g = makecalls(layout_growing, fish_growing)
# draw shrinking fish squarelimit
plot( cycle(rot(fishquarters_s)), title="shrinking fish squarelimit level:"+str(i), frame=0)
plot( cycle(rot(fishquarters_g)), title="growing fish squarelimit level:"+str(i), frame=0)