之前觉得不是特别喜欢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()
小彩旗有点丑哈,原想着让小彩旗的三角挨着可是后来发现我忘了等边三角形的高扎求来着了???想想我当年可是班里数学小能手哈