实例2: Python蟒蛇绘制
使用turtle库绘制一个蟒蛇形状的图形
#PythonDraw.py
import turtle
turtle.setup(650, 350, 200, 200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("purple")
turtle.seth(-40)
for i in range(4):
turtle.circle(40, 80)
turtle.circle(-40, 80)
turtle.circle(40, 80/2)
turtle.fd(40)
turtle.circle(16, 180)
turtle.fd(40 * 2/3)
turtle.done()
turtle正方形绘制
import turtle as t
t.pensize(10)
for i in range(4):
t.fd(100)
t.left(90)
t.done()
使用turtle绘制一个六边形
import turtle as t
t.pensize(10)
for i in range(6):
t.fd(100)
t.left(60) #角度改成60
t.done()
使用turtle库,绘制一个叠边形,其中,叠边形内角为80度
import turtle as t
t.pensize(5)
for i in range(9):
t.fd(150)
t.left(80) #也就是角度变了,多循环了几次
t.done()
单元练习题