首页 > 其他 > 详细

使用turtle库绘制图形

时间:2020-03-12 13:31:44      阅读:88      评论:0      收藏:0      [点我收藏+]

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)

  技术分享图片

使用turtle库绘制图形

原文:https://www.cnblogs.com/cnn-ljc/p/12468209.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!