用Python画出一个学生滑滑板的程序
时间: 2023-10-07 14:08:26 浏览: 140
基于python实现画板程序.zip
5星 · 资源好评率100%
以下是一个简单的Python代码,用turtle库画出一个学生滑滑板的动画:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(600, 400)
turtle.bgcolor("#33ccff")
# 绘制学生
turtle.penup()
turtle.goto(-150, 0)
turtle.pendown()
turtle.color("black")
turtle.fillcolor("#ffcc66")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(-150, -50)
turtle.pendown()
turtle.color("#ffcc66")
turtle.fillcolor("#ffcc66")
turtle.begin_fill()
turtle.circle(25)
turtle.end_fill()
# 绘制滑板
turtle.penup()
turtle.goto(100, -50)
turtle.pendown()
turtle.color("black")
turtle.fillcolor("#999999")
turtle.begin_fill()
turtle.forward(100)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(20)
turtle.end_fill()
# 绘制滑板轮子
turtle.penup()
turtle.goto(125, -70)
turtle.pendown()
turtle.color("black")
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(175, -70)
turtle.pendown()
turtle.color("black")
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 绘制滑板运动的动画
for i in range(30):
turtle.penup()
turtle.goto(100+i*5, -50)
turtle.pendown()
turtle.clear()
turtle.color("black")
turtle.fillcolor("#999999")
turtle.begin_fill()
turtle.forward(100)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(20)
turtle.end_fill()
turtle.penup()
turtle.goto(125+i*5, -70)
turtle.pendown()
turtle.color("black")
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(175+i*5, -70)
turtle.pendown()
turtle.color("black")
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.done()
```
运行这段代码,你会看到一个小学生骑着滑板在移动的动画。你可以尝试修改一些参数,比如学生和滑板的颜色,滑板运动的速度等等,来创造出自己喜欢的效果。
阅读全文