python画五角星
今天刚学python海龟画图,课堂作业画五角星,顺便分享给大家。
运行图片如下:
代码如下:
# 以画布中心为中点,向右为X轴正方向,向上为Y轴正方向
import turtle
turtle.setup(500, 500) # 设置画布尺寸
turtle.pensize(7) # 设置画笔尺寸
turtle.pencolor("yellow") # 设置画笔颜色
turtle.fillcolor("red") # 设置填充颜色
turtle.penup() # 提起画笔
turtle.goto(-120, 50) # 画笔从默认画布中心移动往X轴负方向移动120像素点,往y轴正方向移动50像素点
turtle.pendown() # 放下画笔
turtle.begin_fill() # 画笔开始填充
for i in range(5): # 设置循环次数为5,两条边为一次循环
turtle.fd(100) # 画笔向前画100像素单位
turtle.left(72) # 左拐72度
turtle.fd(100) # 画笔向前画100像素单位
turtle.right(144) # 右拐144度
turtle.end_fill() # 结束填充
turtle.done() # 程序运行完,画布窗体不关闭
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17