Skip to content

Commit 3fe94e7

Browse files
committed
First implementation of shadow map
1 parent e763b1a commit 3fe94e7

File tree

2 files changed

+112
-7
lines changed

2 files changed

+112
-7
lines changed

goban.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,29 @@ def display(self,grid,markup,network,links,freeze=False):
121121
for j in range(dim):
122122
neighbors=neighborhood(i,j,dim)
123123

124+
"""
124125
if network[i][j]==1:
125-
self.draw_point(i,j,0.5,"#8A80D8",outline="#8A80D8")
126+
self.draw_point(i,j,0.2,"#8A80D8",outline="#8A80D8")
126127
127128
if network[i][j]==2:
128-
self.draw_point(i,j,0.5,"#FFF88E",outline="#FFF88E")
129+
self.draw_point(i,j,0.2,"#FFF88E",outline="#FFF88E")
130+
"""
131+
132+
if network[i][j]==3:
133+
self.draw_point(i,j,0.2,"#8A80D8",outline="#8A80D8")
134+
135+
if network[i][j]==4:
136+
self.draw_point(i,j,0.2,"#FFF88E",outline="#FFF88E")
129137

130138
for u,v in neighbors:
131139
if links[p2l(i,j,u,v,dim)]==1:
132140
self.draw_line(i,j,u,v,color="#8A80D8",width=3)
133141
elif links[p2l(i,j,u,v,dim)]==2:
134142
self.draw_line(i,j,u,v,color="#FFF88E",width=3)
135-
143+
elif links[p2l(i,j,u,v,dim)]==3:
144+
self.draw_point(0.5*(i+u),0.5*(j+v),0.2,"#8A80D8",outline="#8A80D8")
145+
elif links[p2l(i,j,u,v,dim)]==4:
146+
self.draw_point(0.5*(i+u),0.5*(j+v),0.2,"#FFF88E",outline="#FFF88E")
136147

137148
for i in range(dim):
138149
for j in range(dim):

gomap.py

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,94 @@ def common_draw_color(self):
141141

142142

143143

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+
144232

145233
from goban import *
146234

@@ -296,6 +384,10 @@ def color_map(self):
296384
self.calculate_color(self)
297385
self.frame+=1
298386

387+
def shadow_map(self):
388+
common_draw_shadow(self)
389+
self.frame+=1
390+
299391
def initialize(self):
300392

301393
self
@@ -319,8 +411,7 @@ def initialize(self):
319411
#Button(panel, text='undo',command=lambda :click_on_undo(self)).grid(column=0,row=1)
320412
Button(panel, text='undo',command=self.undo).grid(column=0,row=1)
321413
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)
324415
Button(panel, text='Export',command=self.save_as_ps).grid(column=0,row=5)
325416

326417
panel.grid(column=0,row=1,sticky=N)
@@ -450,6 +541,10 @@ def color_map(self):
450541
common_draw_color(self)
451542
self.frame+=1
452543

544+
def shadow_map(self):
545+
common_draw_shadow(self)
546+
self.frame+=1
547+
453548
def close_app(self):
454549
for popup in self.all_popups[:]:
455550
popup.close()
@@ -610,8 +705,7 @@ def initialize(self):
610705
self.move_number.grid(column=20,row=3)
611706

612707
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)
615709

616710
Button(buttons_bar, text='Export',command=self.save_as_ps).grid(column=21,row=4)
617711

0 commit comments

Comments
 (0)