这次,我们还是用turtle模块进行绘图
本次教学绘制两个图案(关注Turtle画图该栏目,持续更新绘图教学文章)
一、音符
代码教学:
先导入所需要的模块
import turtle as t
然后,初始化画笔的参数
t.color("black")
t.pensize(5)
开始填充黑色
t.begin_fill()
画前面一个小音符的圆圈
t.left(90)
t.circle(25)
再停止填充
t.end_fill()
画第一个音符的小杆杆
t.fd(150)
转个角度画两个音符的连接线
t.right(80)
t.fd(100)
转个角度画第二个音符的小杆杆
t.right(100)
t.fd(150)
画一个小黑圆
t.begin_fill()
t.circle(-25)
t.end_fill()
最后,隐藏画笔保持窗口显示状态
t.hideturtle()
t.done()
最终代码:
import turtle as t
t.color("black")
t.pensize(5)
t.begin_fill()
t.left(90)
t.circle(25)
t.end_fill()
t.fd(150)
t.right(80)
t.fd(100)
t.right(100)
t.fd(150)
t.begin_fill()
t.circle(-25)
t.end_fill()
t.hideturtle()
t.done()
二、雪人
代码讲解:
导入所需要的模块
import turtle as t
初始化画笔
t.speed(0)
t.pensize(5)
绘制雪人的头和身体
t.circle(50)
t.circle(-100)
绘制雪人的纽扣
for i in range(4):
t.right(90)
t.pu()
t.fd(40)
t.pd()
t.left(90)
t.begin_fill()
t.circle(-10)
t.end_fill()
绘制雪人的眼睛
t.pu()
t.goto(20,70)
t.pd()
t.dot(10,"black")
绘制雪人的鼻子
t.pu()
t.goto(40,60)
t.pd()
t.fillcolor("orange")
t.begin_fill()
t.left(180)
t.circle(10,180)
t.left(15)
t.fd(80)
t.goto(40,60)
t.end_fill()
绘制雪人的手
t.pu()
t.goto(-35,-35)
t.setheading(225)
t.pd()
t.fd(130)
t.right(30)
for i in range(3):
t.fd(20)
t.bk(20)
t.left(30)
隐藏画笔并保持窗口显示状态
t.hideturtle()
t.done()
最终代码:
import turtle as t
t.speed(0)
t.pensize(5)
t.circle(50)
t.circle(-100)
for i in range(4):
t.right(90)
t.pu()
t.fd(40)
t.pd()
t.left(90)
t.begin_fill()
t.circle(-10)
t.end_fill()
t.pu()
t.goto(20,70)
t.pd()
t.dot(10,"black")
t.pu()
t.goto(40,60)
t.pd()
t.fillcolor("orange")
t.begin_fill()
t.left(180)
t.circle(10,180)
t.left(15)
t.fd(80)
t.goto(40,60)
t.end_fill()
t.pu()
t.goto(-35,-35)
t.setheading(225)
t.pd()
t.fd(130)
t.right(30)
for i in range(3):
t.fd(20)
t.bk(20)
t.left(30)
t.hideturtle()
t.done()