Signed-off-by: sairate <sairate@sina.cn>
This commit is contained in:
commit
e680fccb29
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MaterialThemeProjectNewConfig">
|
||||||
|
<option name="metadata">
|
||||||
|
<MTProjectMetadataState>
|
||||||
|
<option name="userId" value="4074489c:1944f2d94b0:-7ef0" />
|
||||||
|
</MTProjectMetadataState>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/雪花动画.iml" filepath="$PROJECT_DIR$/.idea/雪花动画.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -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()
|
Loading…
Reference in New Issue