@@ -141,6 +141,94 @@ def common_draw_color(self):
141
141
142
142
143
143
144
+ def common_draw_shadow (self ):
145
+ dim = self .dim
146
+
147
+ network = self .network
148
+ links = self .links
149
+
150
+ #Each singly-coloured point shadows its links to empty points
151
+ for i in range (dim ):
152
+ for j in range (dim ):
153
+ if self .network [i ][j ]== 0 : #this is an empty point (singly colored point must be empty)
154
+ neighbors = goban .neighborhood (i ,j ,dim )
155
+ count_black = 0
156
+ count_white = 0
157
+ count_grey = 0
158
+ for u ,v in neighbors :
159
+ if links [p2l (i ,j ,u ,v ,dim )]== 1 :
160
+ count_black += 1
161
+ elif links [p2l (i ,j ,u ,v ,dim )]== 2 :
162
+ count_white += 1
163
+ elif links [p2l (i ,j ,u ,v ,dim )]== 1.5 :
164
+ count_grey += 1
165
+ if count_black > 0 and count_white == 0 and count_grey == 0 :
166
+ #this is a singly colored black point
167
+ for u ,v in neighbors :
168
+ if self .network [u ][v ]<= 0 :
169
+ if links [p2l (i ,j ,u ,v ,dim )] in [0 ,3 ]:
170
+ links [p2l (i ,j ,u ,v ,dim )]= 3
171
+ elif links [p2l (i ,j ,u ,v ,dim )]== 4 :
172
+ links [p2l (i ,j ,u ,v ,dim )]= 3.5
173
+
174
+ elif count_black == 0 and count_white > 0 and count_grey == 0 :
175
+ #this is a singly colored white point
176
+ for u ,v in neighbors :
177
+ if self .network [u ][v ]<= 0 :
178
+ if links [p2l (i ,j ,u ,v ,dim )] in [0 ,4 ]:
179
+ links [p2l (i ,j ,u ,v ,dim )]= 4
180
+ elif links [p2l (i ,j ,u ,v ,dim )]== 3 :
181
+ links [p2l (i ,j ,u ,v ,dim )]= 3.5
182
+
183
+
184
+ #a point whose links are multiply shadowed by only one colour becomes a shadowed point.
185
+ for i in range (dim ):
186
+ for j in range (dim ):
187
+ if self .network [i ][j ]== 0 : #this is an empty point (singly shadowed point must be empty)
188
+ neighbors = goban .neighborhood (i ,j ,dim )
189
+ count_black = 0
190
+ count_white = 0
191
+ count_other = 0
192
+ for u ,v in neighbors :
193
+ if links [p2l (i ,j ,u ,v ,dim )] in [1 ,3 ]:
194
+ count_black += 1
195
+ elif links [p2l (i ,j ,u ,v ,dim )] in [2 ,4 ]:
196
+ count_white += 1
197
+ elif links [p2l (i ,j ,u ,v ,dim )] in [1.5 ,3.5 ]:
198
+ count_other += 1
199
+
200
+ if count_black > 1 and count_white == 0 and count_other == 0 :
201
+ #this is a singly shadowed black point
202
+ self .network [i ][j ]= 3
203
+
204
+ elif count_black == 0 and count_white > 1 and count_other == 0 :
205
+ #this is a singly shadowed white point
206
+ self .network [i ][j ]= 4
207
+
208
+ #a shadowed point propagates its shadow along its unshadowed links.
209
+ for i in range (dim ):
210
+ for j in range (dim ):
211
+ if self .network [i ][j ]== 3 :
212
+ neighbors = goban .neighborhood (i ,j ,dim )
213
+ for u ,v in neighbors :
214
+ if links [p2l (i ,j ,u ,v ,dim )] in [0 ,3 ]:
215
+ links [p2l (i ,j ,u ,v ,dim )]= 3
216
+ elif links [p2l (i ,j ,u ,v ,dim )]== 4 :
217
+ links [p2l (i ,j ,u ,v ,dim )]= 3.5
218
+
219
+ elif self .network [i ][j ]== 4 :
220
+ neighbors = goban .neighborhood (i ,j ,dim )
221
+ for u ,v in neighbors :
222
+ if links [p2l (i ,j ,u ,v ,dim )] in [0 ,4 ]:
223
+ links [p2l (i ,j ,u ,v ,dim )]= 4
224
+ elif links [p2l (i ,j ,u ,v ,dim )]== 3 :
225
+ links [p2l (i ,j ,u ,v ,dim )]= 3.5
226
+
227
+ self .goban .display (self .grid ,self .markup ,self .network ,self .links )
228
+
229
+
230
+
231
+
144
232
145
233
from goban import *
146
234
@@ -296,6 +384,10 @@ def color_map(self):
296
384
self .calculate_color (self )
297
385
self .frame += 1
298
386
387
+ def shadow_map (self ):
388
+ common_draw_shadow (self )
389
+ self .frame += 1
390
+
299
391
def initialize (self ):
300
392
301
393
self
@@ -319,8 +411,7 @@ def initialize(self):
319
411
#Button(panel, text='undo',command=lambda :click_on_undo(self)).grid(column=0,row=1)
320
412
Button (panel , text = 'undo' ,command = self .undo ).grid (column = 0 ,row = 1 )
321
413
Button (panel , text = ' Color ' ,command = self .color_map ).grid (column = 0 ,row = 2 )
322
- #Button(panel, text='Cluster').grid(column=0,row=3)
323
- #Button(panel, text='Shadow ').grid(column=0,row=4)
414
+ Button (panel , text = 'Shadow ' ,command = self .shadow_map ).grid (column = 0 ,row = 4 )
324
415
Button (panel , text = 'Export' ,command = self .save_as_ps ).grid (column = 0 ,row = 5 )
325
416
326
417
panel .grid (column = 0 ,row = 1 ,sticky = N )
@@ -450,6 +541,10 @@ def color_map(self):
450
541
common_draw_color (self )
451
542
self .frame += 1
452
543
544
+ def shadow_map (self ):
545
+ common_draw_shadow (self )
546
+ self .frame += 1
547
+
453
548
def close_app (self ):
454
549
for popup in self .all_popups [:]:
455
550
popup .close ()
@@ -610,8 +705,7 @@ def initialize(self):
610
705
self .move_number .grid (column = 20 ,row = 3 )
611
706
612
707
Button (buttons_bar , text = ' Color ' ,command = self .color_map ).grid (column = 19 ,row = 4 )
613
- #Button(buttons_bar, text='Cluster').grid(column=20,row=4)
614
- #Button(buttons_bar, text='Shadow ').grid(column=21,row=4)
708
+ Button (buttons_bar , text = 'Shadow ' ,command = self .shadow_map ).grid (column = 20 ,row = 4 )
615
709
616
710
Button (buttons_bar , text = 'Export' ,command = self .save_as_ps ).grid (column = 21 ,row = 4 )
617
711
0 commit comments