当前位置:   article > 正文

Python Turtle 小项目 8 各种音符的绘制_python音符代码

python音符代码

本次,我们将继续使用Turtle模块进行绘制,下面将教学如何绘制各种音符

 

 


 一、一个四分音符

效果:

代码讲解:

1.导入模块

from turtle import *

 2.设置属性

pensize(4)

3. 绘制圆圈

  1. begin_fill()
  2. circle(40,450)
  3. end_fill()

4.绘制线段

fd(180)

5.隐藏画笔,保持窗口显示

  1. ht()
  2. done()

最终代码

  1. from turtle import *
  2. pensize(4)
  3. begin_fill()
  4. circle(40,450)
  5. end_fill()
  6. fd(180)
  7. ht()
  8. done()

 难度:※ x1


二、一个八分音符

效果:

代码讲解:

在上面画四分音符的代码中添加三行代码,最终代码:

  1. from turtle import *
  2. pensize(4)
  3. begin_fill()
  4. circle(40,450)
  5. end_fill()
  6. fd(180)
  7. right(180) # 添加的代码
  8. circle(80,40) # 添加的代码
  9. circle(-80,45) # 添加的代码
  10. ht()
  11. done()

 难度:※ x1


三、两个八分音符

效果:

代码讲解:

1.导入模块

from turtle import *

 2.设置属性

pensize(6)

3.绘制圆圈

  1. begin_fill()
  2. circle(40,450)
  3. end_fill()

 4.绘制三条线段

  1. fd(180)
  2. right(75)
  3. fd(180)
  4. right(105)
  5. fd(180)

5.绘制圆圈

  1. begin_fill()
  2. circle(-40)
  3. end_fill()

6.隐藏画笔并保持窗口显示

  1. ht()
  2. done()

 最终代码:

  1. from turtle import *
  2. pensize(6)
  3. begin_fill()
  4. circle(40,450)
  5. end_fill()
  6. fd(180)
  7. right(75)
  8. fd(180)
  9. right(105)
  10. fd(180)
  11. begin_fill()
  12. circle(-40)
  13. end_fill()
  14. ht()
  15. done()

难度:※ x1.5 


四、三连音

效果:

代码讲解:

1.导入模块

from turtle import *

 2.设置属性

pensize(6)

3.绘制第一个圆

  1. begin_fill()
  2. circle(40,450)
  3. end_fill()

 4.绘制三条线段

  1. fd(180)
  2. right(75)
  3. p=pos()
  4. fd(180)
  5. right(105)
  6. p2=pos()
  7. fd(180)

5.绘制第二个圆

  1. begin_fill()
  2. circle(-40)
  3. end_fill()

 6.移动到刚刚画的第二条线段的结束端点位置

  1. pu()
  2. goto(p2)
  3. pd()

7.绘制两条线段

  1. left(105)
  2. fd(180)
  3. right(105)
  4. p3=pos()
  5. fd(180)

 8.绘制第三个圆

  1. begin_fill()
  2. circle(-40)
  3. end_fill()

难点开始:

9.首先,移动到第一个圆圈上面线段结束端点的上面20像素的位置,然后向上画一条40像素的线段,作为3连音左边界限

10.然后,移动到该线段的中点,和下面斜着的线段平行绘制160像素的线段,留出距离三个音符中点的20像素位置。

11.绘制数字“3”。

12.根据第十步,先抬笔,留出距离中点20像素的位置,然后落笔,绘制和下面斜着的线段平行的160像素的线段。

13.根据第九步,绘制右界限,方法与第九步没有太大差别,这里不做详细讲解。

难点结束。难点部分代码如下:

  1. pu()
  2. goto(p)
  3. seth(90)
  4. fd(20)
  5. pd()
  6. fd(40)
  7. bk(20)
  8. right(75)
  9. fd(150)
  10. pu()
  11. fd(30)
  12. write("3",align="center",font=("Dengxian",35,"bold"))
  13. fd(30)
  14. pd()
  15. fd(150)
  16. left(75)
  17. fd(20)
  18. bk(40)

14.最后,隐藏画笔并保持窗口显示状态。

  1. ht()
  2. done()

最终代码:

  1. from turtle import *
  2. pensize(6)
  3. begin_fill()
  4. circle(40,450)
  5. end_fill()
  6. fd(180)
  7. right(75)
  8. p=pos()
  9. fd(180)
  10. right(105)
  11. p2=pos()
  12. fd(180)
  13. begin_fill()
  14. circle(-40)
  15. end_fill()
  16. pu()
  17. goto(p2)
  18. pd()
  19. left(105)
  20. fd(180)
  21. right(105)
  22. p3=pos()
  23. fd(180)
  24. begin_fill()
  25. circle(-40)
  26. end_fill()
  27. pu()
  28. goto(p)
  29. seth(90)
  30. fd(20)
  31. pd()
  32. fd(40)
  33. bk(20)
  34. right(75)
  35. fd(150)
  36. pu()
  37. fd(30)
  38. write("3",align="center",font=("Dengxian",35,"bold"))
  39. fd(30)
  40. pd()
  41. fd(150)
  42. left(75)
  43. fd(20)
  44. bk(40)
  45. ht()
  46. done()

难度:※ x2.5 


五、十六分音符

效果:

代码讲解:

1.导入模块

from turtle import *

 2.根据绘制八分音符的代码,在此基础上稍作更改,详情请见代码中注释:

  1. pensize(6)
  2. begin_fill()
  3. circle(40,450)
  4. end_fill()
  5. fd(180)
  6. right(75)
  7. fd(180)
  8. right(105)
  9. fd(30) # 先移动30像素
  10. p=pos() # 获取该位置坐标,待会儿可以从这里开始绘制16分音符比8分音符多的一条线段
  11. fd(150) # 再移动150像素,凑满180像素
  12. begin_fill()
  13. circle(-40)
  14. end_fill()

3.移到变量p的位置,绘制多出来的线段。

  1. pu()
  2. goto(p)
  3. pd()
  4. right(75)
  5. fd(180)

4.隐藏画笔并保持窗口显示

  1. ht()
  2. done()

 最终代码:

  1. from turtle import *
  2. pensize(6)
  3. begin_fill()
  4. circle(40,450)
  5. end_fill()
  6. fd(180)
  7. right(75)
  8. fd(180)
  9. right(105)
  10. fd(30)
  11. p=pos()
  12. fd(150)
  13. begin_fill()
  14. circle(-40)
  15. end_fill()
  16. pu()
  17. goto(p)
  18. pd()
  19. right(75)
  20. fd(180)
  21. ht()
  22. done()

难度:※ x1.25 


六、一个十六分音符

效果:

代码讲解:

1.导入模块

from turtle import *

 2.设置属性

pensize(6)

3.绘制圆圈

  1. begin_fill()
  2. circle(40,450)
  3. end_fill()

 4.绘制线段,并获取坐标

  1. fd(140)
  2. p=pos()
  3. fd(40)
  4. right(180)

5.绘制弧线

  1. circle(80,40)
  2. circle(-80,45)

 6.绘制第二条曲线

  1. pu()
  2. goto(p)
  3. pd()
  4. seth(-90)
  5. circle(80,40)
  6. circle(-80,45)

7.隐藏画笔并保持窗口显示

  1. ht()
  2. done()

最终代码:

  1. from turtle import *
  2. pensize(6)
  3. begin_fill()
  4. circle(40,450)
  5. end_fill()
  6. fd(140)
  7. p=pos()
  8. fd(40)
  9. right(180)
  10. circle(80,40)
  11. circle(-80,45)
  12. pu()
  13. goto(p)
  14. pd()
  15. seth(-90)
  16. circle(80,40)
  17. circle(-80,45)
  18. ht()
  19. done()

 难度:※ x1.25


七、八分休止符

效果:

代码讲解

1.导入模块

from turtle import *

 2.设置属性

pensize(6)

3.绘制圆圈

  1. begin_fill()
  2. circle(20)
  3. end_fill()

4.绘制弧线

circle(90,40)

 5.绘制线段

  1. seth(-115)
  2. fd(120)

6.隐藏画笔并保持窗口显示

  1. ht()
  2. done()

最终代码:

  1. from turtle import *
  2. pensize(6)
  3. begin_fill()
  4. circle(20)
  5. end_fill()
  6. circle(90,40)
  7. seth(-115)
  8. fd(120)
  9. ht()
  10. done()

 难度:※ x1


八、二分休止符

效果:

代码讲解:

1.导入模块

from turtle import *

 2.设置属性

pensize(6)

3.绘制长方形左边的线段

fd(30)

 4.绘制长方形

  1. begin_fill()
  2. for i in range(2):
  3. fd(90)
  4. left(90)
  5. fd(10)
  6. left(90)
  7. end_fill()

5.移动到长方形右下角

fd(90)

 6.绘制长方形右边的线段

fd(30)

7.隐藏画笔并保持窗口显示

  1. ht()
  2. done()

 最终代码:

  1. from turtle import *
  2. pensize(6)
  3. fd(30)
  4. begin_fill()
  5. for i in range(2):
  6. fd(90)
  7. left(90)
  8. fd(10)
  9. left(90)
  10. end_fill()
  11. fd(90)
  12. fd(30)
  13. ht()
  14. done()

难度:※ x1.25 

拓展:全休止符

效果:

代码和二分休止符差不多,在此基础上修改,把循环中的left改为right,代码如下:

  1. from turtle import *
  2. pensize(6)
  3. fd(30)
  4. begin_fill()
  5. for i in range(2):
  6. fd(90)
  7. right(90)
  8. fd(10)
  9. right(90)
  10. end_fill()
  11. fd(90)
  12. fd(30)
  13. ht()
  14. done()

 难度:※ x1.25


九、十六分休止符

效果:

代码讲解:

1.导入模块

from turtle import *

2.设置属性

pensize(6)

 3.绘制圆圈

  1. begin_fill()
  2. circle(20)
  3. end_fill()

4.绘制弧线和线段

  1. circle(90,40)
  2. h=heading()
  3. seth(-115)
  4. fd(80)
  5. p=pos()

 5.绘制弧线

  1. seth(h)
  2. circle(90,-40)

6.绘制圆圈

  1. begin_fill()
  2. circle(20)
  3. end_fill()

 7.设置上一条线段的结束端点为开始端点继续绘制线段

  1. pu()
  2. goto(p)
  3. pd()
  4. seth(-115)
  5. fd(80)

8.隐藏画笔并保持窗口显示

  1. ht()
  2. done()

 最终代码:

  1. from turtle import *
  2. pensize(6)
  3. begin_fill()
  4. circle(20)
  5. end_fill()
  6. circle(90,40)
  7. h=heading()
  8. seth(-115)
  9. fd(80)
  10. p=pos()
  11. seth(h)
  12. circle(90,-40)
  13. begin_fill()
  14. circle(20)
  15. end_fill()
  16. pu()
  17. goto(p)
  18. pd()
  19. seth(-115)
  20. fd(80)
  21. ht()
  22. done()

难度:※ x2 


十、高音谱号

效果:

由多条弧线和线段组成,这里不做详细讲解,最终代码:

  1. from turtle import *
  2. pensize(5)
  3. seth(115)
  4. circle(-30,220)
  5. circle(-50,220)
  6. fd(70)
  7. circle(50,100)
  8. seth(-145)
  9. circle(50,58)
  10. fd(200)
  11. circle(-30,180)
  12. begin_fill()
  13. circle(-10)
  14. end_fill()
  15. ht()
  16. 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


制作不易,喜欢的话记得点赞关注哦!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/788514
推荐阅读
相关标签
  

闽ICP备14008679号