python turtle库-绘图

之前觉得不是特别喜欢python,现在越发觉得python是那么的有趣

利用python turtle库绘图

五角星

from turtle import * #导入turtle库(python作图的库)
color("red","red")   #设置前景色和后景色
begin_fill()         #开始填充
for i in range(5):   
    fd(300) #fd 方法的实参是像素距离      
    rt(144)
end_fill()

注:python中rt是open()函数打开文件的一种模式,rt模式下,python在读取文本时会自动把\r\n转换成\n,文本文件用二进制读取用‘rt

python颜色对照

五角形和六边形

from turtle import * #导入turtle库(python作图的库)
color("red","red")   #设置前景色和后景色
begin_fill()         #开始填充
for i in range(5):   
    fd(300) #fd 方法的实参是像素距离      
    rt(144) #python中rt是open()函数打开文件的一种模式,rt模式下,python在读取文本时会自动把\r\n转换成\n,文本文件用二进制读取用‘rt
end_fill()
up()             #提起画笔 注释掉会连着画
goto(-200,100)   #移动画笔
down()           #落下画笔
color("red","teal")   
begin_fill()         
for i in range(6):   
    fd(100)       
    rt(60)
end_fill()

from turtle import * #导入turtle库(python作图的库)
color("red","red")   #设置前景色和后景色
begin_fill()         #开始填充
for i in range(5):   
	fd(150) #fd 方法的实参是像素距离      
	rt(144) #python中rt是open()函数打开文件的一种模式,rt模式下,python在读取文本时会自动把\r\n转换成\n,文本文件用二进制读取用‘rt
end_fill()
#up()             #提起画笔 注释就连着画
goto(-200,100)   #移动画笔
#down()           #落下画笔
color("red","teal")   
begin_fill()         
for i in range(6):   
	fd(100)       
	rt(60)
end_fill()
goto(-400,100)   #移动画笔
#down()           #落下画笔
color("yellow","blue")   
begin_fill()         
for i in range(4):   
	fd(150)       
	rt(90)
end_fill()
goto(-600,100)   #移动画笔
#down()           #落下画笔
color("red","green")   
begin_fill()         
for i in range(3):   
	fd(150)       
	rt(120)
end_fill()

小彩旗

from turtle import * #导入turtle库(python作图的库)
goto(0,-300)   #移动画笔
color("blue","aqua")   
begin_fill()         
for i in range(3):   
	fd(100)       
	rt(120)
end_fill()
goto(0,-200)   #移动画笔
color("gold","brown")   
begin_fill()         
for i in range(3):   
	fd(100)       
	rt(120)
end_fill()
goto(0,-100)   #移动画笔
color("indigo","limegreen")   
begin_fill()         
for i in range(3):   
	fd(100)       
	rt(120)
end_fill()
goto(0,0)   #移动画笔
color("red","green")   
begin_fill()         
for i in range(3):   
	fd(100)       
	rt(120)
end_fill()
goto(0,100)   #移动画笔
color("cyan","yellow")   
begin_fill()         
for i in range(3):   
	fd(100)       
	rt(120)
end_fill()
goto(0,200)   #移动画笔
color("yellow","red")   
begin_fill()         
for i in range(3):   
	fd(100)       
	rt(120)
end_fill()
goto(0,300)   #移动画笔
color("purple","lime")   
begin_fill()         
for i in range(3):   
	fd(100)       
	rt(120)
end_fill()

小彩旗有点丑哈,原想着让小彩旗的三角挨着可是后来发现我忘了等边三角形的高扎求来着了???想想我当年可是班里数学小能手哈

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值