使用turtle库绘制图形

1.使用turtle库绘制红色五角星图形

import turtle
n = eval(input("请输入五角星的长度"))
turtle.begin_fill() #开始填充颜色
i = 0
while i < 5:
    turtle.forward(n)
    turtle.right(180-36)
    i += 1
turtle.color("red") # 退出填充颜色
turtle.end_fill()
turtle.done()

  

2.使用turtle库绘制六角形图形

from turtle import *
color("black","red") 

begin_fill()
pu()
fd(-200)
pd()
seth(30)
fd(300)
seth(-90)
fd(300)
seth(150)
fd(300)
end_fill()
 
pu()
seth(90)
fd(150)
seth(0)
fd(87)
begin_fill()

pd()
seth(-90)
fd(300)
seth(30)
fd(300)
seth(150)
fd(300)
end_fill()
done()

  

3.使用turtle库绘制叠加等边三角形图形

import turtle as t
t.setup(600, 600, None,None)
t.pu()
t.fd(-120)
t.pensize(5)
t.width(5)
t.pencolor("darkgreen")
t.pd()
t.fd(250)
t.seth(120)
t.pencolor("black")
t.fd(250)
t.seth(-120)
t.pencolor("blue")
t.fd(250)
t.pencolor("purple")
t.fd(250)
t.seth(0)
t.pencolor("green")
t.fd(250)
t.pencolor("gold")
t.fd(250)
t.seth(120)
t.pencolor("yellow")
t.fd(250)
t.seth(-120)
t.pencolor("grey")
t.fd(250)
t.seth(120)
t.pencolor("pink")
t.fd(250)

  

猜你喜欢

转载自www.cnblogs.com/cnn-ljc/p/12468209.html