本次,我们将继续使用Turtle模块进行绘制,下面将教学如何绘制各种音符
一、一个四分音符
效果:
代码讲解:
1.导入模块
from turtle import *
2.设置属性
pensize(4)
3. 绘制圆圈
begin_fill()
circle(40,450)
end_fill()
4.绘制线段
fd(180)
5.隐藏画笔,保持窗口显示
ht()
done()
最终代码
from turtle import *
pensize(4)
begin_fill()
circle(40,450)
end_fill()
fd(180)
ht()
done()
难度:※ x1
二、一个八分音符
效果:
代码讲解:
在上面画四分音符的代码中添加三行代码,最终代码:
from turtle import *
pensize(4)
begin_fill()
circle(40,450)
end_fill()
fd(180)
right(180) # 添加的代码
circle(80,40) # 添加的代码
circle(-80,45) # 添加的代码
ht()
done()
难度:※ x1
三、两个八分音符
效果:
代码讲解:
1.导入模块
from turtle import *
2.设置属性
pensize(6)
3.绘制圆圈
begin_fill()
circle(40,450)
end_fill()
4.绘制三条线段
fd(180)
right(75)
fd(180)
right(105)
fd(180)
5.绘制圆圈
begin_fill()
circle(-40)
end_fill()
6.隐藏画笔并保持窗口显示
ht()
done()
最终代码:
from turtle import *
pensize(6)
begin_fill()
circle(40,450)
end_fill()
fd(180)
right(75)
fd(180)
right(105)
fd(180)
begin_fill()
circle(-40)
end_fill()
ht()
done()
难度:※ x1.5
四、三连音
效果:
代码讲解:
1.导入模块
from turtle import *
2.设置属性
pensize(6)
3.绘制第一个圆
begin_fill()
circle(40,450)
end_fill()
4.绘制三条线段
fd(180)
right(75)
p=pos()
fd(180)
right(105)
p2=pos()
fd(180)
5.绘制第二个圆
begin_fill()
circle(-40)
end_fill()
6.移动到刚刚画的第二条线段的结束端点位置
pu()
goto(p2)
pd()
7.绘制两条线段
left(105)
fd(180)
right(105)
p3=pos()
fd(180)
8.绘制第三个圆
begin_fill()
circle(-40)
end_fill()
难点开始:
9.首先,移动到第一个圆圈上面线段结束端点的上面20像素的位置,然后向上画一条40像素的线段,作为3连音左边界限
10.然后,移动到该线段的中点,和下面斜着的线段平行绘制160像素的线段,留出距离三个音符中点的20像素位置。
11.绘制数字“3”。
12.根据第十步,先抬笔,留出距离中点20像素的位置,然后落笔,绘制和下面斜着的线段平行的160像素的线段。
13.根据第九步,绘制右界限,方法与第九步没有太大差别,这里不做详细讲解。
难点结束。难点部分代码如下:
pu()
goto(p)
seth(90)
fd(20)
pd()
fd(40)
bk(20)
right(75)
fd(150)
pu()
fd(30)
write("3",align="center",font=("Dengxian",35,"bold"))
fd(30)
pd()
fd(150)
left(75)
fd(20)
bk(40)
14.最后,隐藏画笔并保持窗口显示状态。
ht()
done()
最终代码:
from turtle import *
pensize(6)
begin_fill()
circle(40,450)
end_fill()
fd(180)
right(75)
p=pos()
fd(180)
right(105)
p2=pos()
fd(180)
begin_fill()
circle(-40)
end_fill()
pu()
goto(p2)
pd()
left(105)
fd(180)
right(105)
p3=pos()
fd(180)
begin_fill()
circle(-40)
end_fill()
pu()
goto(p)
seth(90)
fd(20)
pd()
fd(40)
bk(20)
right(75)
fd(150)
pu()
fd(30)
write("3",align="center",font=("Dengxian",35,"bold"))
fd(30)
pd()
fd(150)
left(75)
fd(20)
bk(40)
ht()
done()
难度:※ x2.5
五、十六分音符
效果:
代码讲解:
1.导入模块
from turtle import *
2.根据绘制八分音符的代码,在此基础上稍作更改,详情请见代码中注释:
pensize(6)
begin_fill()
circle(40,450)
end_fill()
fd(180)
right(75)
fd(180)
right(105)
fd(30) # 先移动30像素
p=pos() # 获取该位置坐标,待会儿可以从这里开始绘制16分音符比8分音符多的一条线段
fd(150) # 再移动150像素,凑满180像素
begin_fill()
circle(-40)
end_fill()
3.移到变量p的位置,绘制多出来的线段。
pu()
goto(p)
pd()
right(75)
fd(180)
4.隐藏画笔并保持窗口显示
ht()
done()
最终代码:
from turtle import *
pensize(6)
begin_fill()
circle(40,450)
end_fill()
fd(180)
right(75)
fd(180)
right(105)
fd(30)
p=pos()
fd(150)
begin_fill()
circle(-40)
end_fill()
pu()
goto(p)
pd()
right(75)
fd(180)
ht()
done()
难度:※ x1.25
六、一个十六分音符
效果:
代码讲解:
1.导入模块
from turtle import *
2.设置属性
pensize(6)
3.绘制圆圈
begin_fill()
circle(40,450)
end_fill()
4.绘制线段,并获取坐标
fd(140)
p=pos()
fd(40)
right(180)
5.绘制弧线
circle(80,40)
circle(-80,45)
6.绘制第二条曲线
pu()
goto(p)
pd()
seth(-90)
circle(80,40)
circle(-80,45)
7.隐藏画笔并保持窗口显示
ht()
done()
最终代码:
from turtle import *
pensize(6)
begin_fill()
circle(40,450)
end_fill()
fd(140)
p=pos()
fd(40)
right(180)
circle(80,40)
circle(-80,45)
pu()
goto(p)
pd()
seth(-90)
circle(80,40)
circle(-80,45)
ht()
done()
难度:※ x1.25
七、八分休止符
效果:
代码讲解
1.导入模块
from turtle import *
2.设置属性
pensize(6)
3.绘制圆圈
begin_fill()
circle(20)
end_fill()
4.绘制弧线
circle(90,40)
5.绘制线段
seth(-115)
fd(120)
6.隐藏画笔并保持窗口显示
ht()
done()
最终代码:
from turtle import *
pensize(6)
begin_fill()
circle(20)
end_fill()
circle(90,40)
seth(-115)
fd(120)
ht()
done()
难度:※ x1
八、二分休止符
效果:
代码讲解:
1.导入模块
from turtle import *
2.设置属性
pensize(6)
3.绘制长方形左边的线段
fd(30)
4.绘制长方形
begin_fill()
for i in range(2):
fd(90)
left(90)
fd(10)
left(90)
end_fill()
5.移动到长方形右下角
fd(90)
6.绘制长方形右边的线段
fd(30)
7.隐藏画笔并保持窗口显示
ht()
done()
最终代码:
from turtle import *
pensize(6)
fd(30)
begin_fill()
for i in range(2):
fd(90)
left(90)
fd(10)
left(90)
end_fill()
fd(90)
fd(30)
ht()
done()
难度:※ x1.25
拓展:全休止符
效果:
代码和二分休止符差不多,在此基础上修改,把循环中的left改为right,代码如下:
from turtle import *
pensize(6)
fd(30)
begin_fill()
for i in range(2):
fd(90)
right(90)
fd(10)
right(90)
end_fill()
fd(90)
fd(30)
ht()
done()
难度:※ x1.25
九、十六分休止符
效果:
代码讲解:
1.导入模块
from turtle import *
2.设置属性
pensize(6)
3.绘制圆圈
begin_fill()
circle(20)
end_fill()
4.绘制弧线和线段
circle(90,40)
h=heading()
seth(-115)
fd(80)
p=pos()
5.绘制弧线
seth(h)
circle(90,-40)
6.绘制圆圈
begin_fill()
circle(20)
end_fill()
7.设置上一条线段的结束端点为开始端点继续绘制线段
pu()
goto(p)
pd()
seth(-115)
fd(80)
8.隐藏画笔并保持窗口显示
ht()
done()
最终代码:
from turtle import *
pensize(6)
begin_fill()
circle(20)
end_fill()
circle(90,40)
h=heading()
seth(-115)
fd(80)
p=pos()
seth(h)
circle(90,-40)
begin_fill()
circle(20)
end_fill()
pu()
goto(p)
pd()
seth(-115)
fd(80)
ht()
done()
难度:※ x2
十、高音谱号
效果:
由多条弧线和线段组成,这里不做详细讲解,最终代码:
from turtle import *
pensize(5)
seth(115)
circle(-30,220)
circle(-50,220)
fd(70)
circle(50,100)
seth(-145)
circle(50,58)
fd(200)
circle(-30,180)
begin_fill()
circle(-10)
end_fill()
ht()
done()
难度:※ x3
往期文章:
Python Turtle 小项目 6_leleprogrammer的博客-CSDN博客本次用turtle绘制一只龙猫,含代码详细讲解https://blog.csdn.net/leleprogrammer/article/details/122154025Python Turtle 小项目 4_leleprogrammer的博客-CSDN博客用Turtle模块绘制三种水果https://blog.csdn.net/leleprogrammer/article/details/122139346Python Turtle 小项目3_leleprogrammer的博客-CSDN博客这次,我们还是用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..https://blog.csdn.net/leleprogrammer/article/details/122137419Python Turtle 小项目2_leleprogrammer的博客-CSDN博客本次用turtle模块进行绘制一、星空效果:代码讲解:首先导入所需要的模块import turtle as timport random然后设置turtle画笔的属性1.把速度设置到最快2.设置背景为深蓝色3.设置画笔和填充颜色为黄色t.speed(0)t.bgcolor("darkblue") # 背景颜色t.color("yellow") # 颜色定义一个star函数绘制星星def star(): # 星星函数 t.penu.https://blog.csdn.net/leleprogrammer/article/details/121840596Python turtle 小项目_leleprogrammer的博客-CSDN博客_python turtle项目Turtle模块画漂亮的图形。https://blog.csdn.net/leleprogrammer/article/details/121434818