Draw a five-pointed red star graphic (Python)

#Five_Star.py   
from turtle import *       #导入turtle库
pensize(10)                 #设置画笔的宽度
begin_fill()                #开始绘画
pencolor('red')             #设置画笔颜色
fillcolor('yellow')         #设置填充颜色
for i in range(5):         #设置一个循环
    fd(200)                 #向当前画笔方向移动200像素长度
    right(144)              #画笔顺时针旋转144度
end_fill()                  #绘画结束
hideturtle()                #隐藏画笔
don()

Program running results:

Remove the middle line and draw along the outermost outline with a paintbrush.

#Five_Star.py   
from turtle import *       #导入turtle库
pensize(2)                 #设置画笔的宽度
begin_fill()                #开始绘画
pencolor('red')             #设置画笔颜色
fillcolor('yellow')         #设置填充颜色
up()                 #把画笔拿起来
goto(0,0)            #将画笔移动到坐标为x,y的位置
down()               #把画笔放下画
for i in range(5):         #设置一个循环
    fd(100)                 #向当前画笔方向移动100像素长度
    left(72)                #画笔逆时针旋转72度
    fd(100)
    right(144)              #画笔顺时针旋转144度
end_fill()                  #绘画结束
hideturtle()                #隐藏画笔
done()

The result of running the program:

Method 3:

#Five_Star.py   
from turtle import *       #导入turtle库
begin_fill()                #开始绘画
color('red','red')          #设置画笔颜色,填充颜色
for i in range(5):         #设置一个循环
    fd(200)                 #向当前画笔方向移动200像素长度
    right(144)              #画笔顺时针旋转144度
end_fill()                  #绘画结束
hideturtle()                #隐藏画笔
done()

Results of running the program:

Guess you like

Origin blog.csdn.net/greatau/article/details/133756423