commit e680fccb290720e46e4c785ae22f5c8d7b71218e Author: sairate Date: Fri Jan 10 16:26:24 2025 +0800 Signed-off-by: sairate diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..eaad5ab --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..23231ce --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0b5756d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/雪花动画.iml b/.idea/雪花动画.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/雪花动画.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/dy.gif b/dy.gif new file mode 100644 index 0000000..83d367e Binary files /dev/null and b/dy.gif differ diff --git a/dy.jpg b/dy.jpg new file mode 100644 index 0000000..32f7379 Binary files /dev/null and b/dy.jpg differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..dd98345 --- /dev/null +++ b/main.py @@ -0,0 +1,61 @@ +import turtle +import random +import time +from PIL import Image + +# 设置屏幕 +screen = turtle.Screen() +screen.setup(width=800, height=600) +screen.bgcolor("black") # 背景色可以设置为黑色或其他 +screen.title("Snowfall Animation") +screen.tracer(0) + +# 加载 .jpg 图片并转换为 .gif 格式 +image_path = "dy.jpg" +image = Image.open(image_path) +# 将图片保存为 .gif 格式 +image.save("dy.gif", "GIF") + +# 设置背景图为 .gif 格式 +screen.bgpic("dy.gif") + +# 创建雪花类 +class Snowflake(turtle.Turtle): + def __init__(self): + super().__init__() + self.hideturtle() + self.penup() + self.speed(0) + self.goto(random.randint(-400, 400), random.randint(100, 300)) + self.size = random.uniform(0.5, 1.5) + self.fall_speed = random.uniform(1, 3) + self.create_snowflake() + + def create_snowflake(self): + self.clear() + self.color("white") + self.shape("circle") # 设置雪花为圆形 + self.shapesize(self.size) + self.showturtle() + + def fall(self): + new_y = self.ycor() - self.fall_speed + if new_y < -300: + # 雪花重新回到顶部 + new_x = random.randint(-400, 400) + self.goto(new_x, random.randint(100, 300)) + else: + self.goto(self.xcor(), new_y) + +# 创建多个雪花 +snowflakes = [Snowflake() for _ in range(50)] + +# 动画循环 +while True: + for snowflake in snowflakes: + snowflake.fall() + screen.update() + time.sleep(0.03) + +# 关闭窗口 +screen.mainloop()