#创建爱心粒子效果层数和抖动效果
for _ in range(halo_number):
t = random.uniform(0, 2 * pi)
x, y = heart_function(t, shrink_ratio=11.6) # alg
x, y = shrink(x, y, halo_radius)
if (x, y) not in heart_halo_point:
# new pts
heart_halo_point.add((x, y))
x += random.randint(-14, 14)
y += random.randint(-14, 14)
size = random.choice((1, 2, 2))
all_points.append((x, y, size))
# 轮廓
for x, y in self._points:
x, y = self.calc_position(x, y, ratio)
size = random.randint(1, 3)
all_points.append((x, y, size))
# content
#历遍边缘效果点集合,加入画布显示点集合
for x, y in self._edge_diffusion_points:
x, y = self.calc_position(x, y, ratio)
size = random.randint(1, 2)
all_points.append((x, y, size))
#历遍中心效果点集合,加入画布显示点集合
for x, y in self._center_diffusion_points:
x, y = self.calc_position(x, y, ratio)
size = random.randint(1, 2)
all_points.append((x, y, size))
self.all_points[generate_frame] = all_points
##历遍爱心点集,对爱心点集填充颜色和定义大小
def render(self, render_canvas, render_frame):
for x, y, size in self.all_points[render_frame % self.generate_frame]:
render_canvas.create_rectangle(x, y, x + size, y + size, width=0, fill=random.choice(HEART_COLOR_LIST))
def draw(main: Tk, render_canvas: Canvas, render_heart: Heart, render_frame=0):
render_canvas.delete('all')
render_heart.render(render_canvas, render_frame)
main.after(70, draw, main, render_canvas, render_heart, render_frame + 1)
if __name__ == '__main__':
root = Tk() # Tk
#画布创建
canvas = Canvas(root, bg='black', height=CANVAS_HEIGHT, width=CANVAS_WIDTH)
canvas.pack()
# 爱心点集创建
heart = Heart()
#爱心生成
draw(root, canvas, heart) # draw
#生成并添加文字标签
text1 = Label(root, text="By SilverPriest ᏊˊꈊˋᏊ", font=("Helvetica", 18), fg="#c12bec", bg="black")
text1.place(x=650, y=500)
text2 = Label(root, text="爱你", font=("Helvetica", 18), fg="#c12bec", bg="black") #
text2.place(x=460, y=350)
root.mainloop()