中秋节仙女给你送月饼了。本动画的显示顺序:首先云彩缓慢地从左边不断移动,然后明月几时有的诗词缓慢移入,最后仙女端着月饼从右边移进。可以加上一个明月几时有的音乐。
以下是部分代码预览:
"""中秋节的夜空云彩和仙女慢慢出现,这是用海龟画图像块制作的一个小动画.""" from turtle import Turtle,Screen def slide_cloud(t): t.setx(t.xcor() + 1) if t.xcor() > t.screen.window_width() // 2 + 300: t.hideturtle() t.setx(-100 - t.screen.window_width() // 2) t.showturtle() if hasattr(t,'name') : # 如果有这个属性,说明它是诗 if t.xcor() ==0 :return t.screen.ontimer(lambda :slide_cloud(t),100) def slide_fairy(t): t.setx(t.xcor() - 1) if t.xcor() < -t.screen.window_width() // 2 - 300: t.hideturtle() return t.screen.ontimer(lambda :slide_fairy(t),100) fairy = "仙女.gif" cloud1 = "云1.gif" cloud2 = "云2.gif" cloud3 = "云3.gif" poem = "明月几时有x.gif" images = [fairy,cloud1,cloud2,cloud3,poem] width ,height = 800,600 screen = Screen() screen.setup(width,height) screen.title("中秋节的夜空云彩和仙女慢慢出现 by lixingqiu") screen.bgcolor("black") screen.bgpic('中秋夜空.png') screen.delay(0) [screen.addshape(image) for image in images] t_cloud1 = Turtle(shape = cloud1,visible=False) t_cloud1.penup() t_cloud1.goto(-800,100) t_cloud1.showturtle() slide_cloud(t_cloud1) t_cloud2 = Turtle(shape = cloud2,visible=False) t_cloud2.penup() t_cloud2.goto(-900,200) t_cloud2.showturtle() slide_cloud(t_cloud2) t_cloud3 = Turtle(shape = cloud3,visible=False) t_cloud3.penup() t_cloud3.goto(-600,000) t_cloud3.showturtle() slide_cloud(t_cloud3) t_poem = Turtle(shape = poem,visible=False) t_poem.name = "我是诗" t_poem.penup() t_poem.goto(-1400,50) t_poem.showturtle() slide_cloud(t_poem) t_fairy = Turtle(shape = fairy,visible=False) t_fairy.penup() t_fairy.goto(2000,0) t_fairy.showturtle() slide_fairy(t_fairy) screen.mainloop()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)