def flood_fill_start_marker(self, starting_point, base_color):
marker_color = pil_color('#ffc688')
#marker_color = pil_color(base_color)
marker_color = tuple([min(marker_color[i], 255) for i in range(3)])
start_area_view = ui.ImageView(frame=self.bounds)
start_area_view.touch_enabled = False
with io.BytesIO(snapshot(start_area_view).to_png()) as fp:
pil = pilImage.open(fp).resize((int(self.width), int(self.height)))
canvas = pil.load()
starting_point = inttuple(starting_point)
canvas[starting_point] = marker_color + (125,)
edge = [starting_point]
sp_vector = Vector(starting_point)
while edge:
newedge = []
for (x, y) in edge:
for candidate in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)):
distance = sp_vector.distance_to(candidate)
if distance <= 15 and self.playfield[candidate][3] == 0 and canvas[candidate][3] == 0:
ceil_dist = math.ceil(distance)
if ceil_dist == 15:
color = pil_color((1,1,1,0.9))
elif ceil_dist == 14:
color = pil_color((0.5,0.5,0.5,0.9))
elif ceil_dist == 13:
color = pil_color((0,0,0,0.9))
elif ceil_dist == 12:
color = pil_color((0.5,0.5,0.5,0.9))
else:
color = pil_color((1,1,1,0.01))
canvas[candidate] = color
#canvas[candidate] = marker_color + (125,) #(int(10+230/15*distance), )
newedge.append(candidate)
edge = newedge
with io.BytesIO() as fp:
pil.save(fp, 'PNG')
start_area_view.image = ui.Image.from_data(fp.getvalue())
self.add_subview(start_area_view)
return canvas
#class TimedVectorPlayingLayer(PlayingLayer):
评论列表
文章目录