Python Turtle small project 8 drawing of various notes

This time, we will continue to draw with the Turtle module. Next, we will teach how to draw various notes

 

 

A quarter note

effect:

Code explanation:

1. Import module

from turtle import *

 2. set a property

pensize(4)

3. Draw a circle

begin_fill()
circle(40,450)
end_fill()

4. Draw line segments

fd(180)

5. Hide the brush and keep the window displayed

ht()
done()

Final code

from turtle import *

pensize(4)
begin_fill()
circle(40,450)
end_fill()
fd(180)

ht()
done()

Difficulty: ※ x1

2, An octave

effect:

Code explanation:

Add three lines of code to the code with quarter notes above, and the final code is:

from turtle import *

pensize(4)
begin_fill()
circle(40,450)
end_fill()
fd(180)
right(180) # Added code
circle(80,40) # Added code
circle(-80,45) # Added code

ht()
done()

Difficulty: ※ x1

3, Two quavers

effect:

Code explanation:

1. Import module

from turtle import *

 2. set a property

pensize(6)

3. Draw a circle

begin_fill()
circle(40,450)
end_fill()

 4. Draw three segments

fd(180)
right(75)
fd(180)
right(105)
fd(180)

5. Draw a circle

begin_fill()
circle(-40)
end_fill()

6. Hide the brush and keep the window displayed

ht()
done()

Final code:

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()

Difficulty: ※ x1 5 

4, Triplet

effect:

Code explanation:

1. Import module

from turtle import *

 2. set a property

pensize(6)

3. Draw the first circle

begin_fill()
circle(40,450)
end_fill()

 4. Draw three segments

fd(180)
right(75)
p=pos()
fd(180)
right(105)
p2=pos()
fd(180)

5. Draw the second circle

begin_fill()
circle(-40)
end_fill()

 6. Move to the end of the second line segment just drawn

pu()
goto(p2)
pd()

7. Draw two line segments

left(105)
fd(180)
right(105)
p3=pos()
fd(180)

 8. Draw the third circle

begin_fill()
circle(-40)
end_fill()

Difficulties start:

9. First, move to the position of 20 pixels above the end point of the line segment above the first circle, and then draw a 40 pixel line segment upward as the left boundary of the 3-tone

10. Then, move to the midpoint of the line segment, draw a 160 pixel line segment parallel to the oblique line segment below, leaving a 20 pixel position from the midpoint of the three notes.

11. Draw the number "3".

12. According to step 10, first lift the pen to leave a position 20 pixels away from the midpoint, and then drop the pen to draw a 160 pixel line segment parallel to the oblique line segment below.

13. Draw the right boundary according to step 9. The method is not much different from step 9, and will not be explained in detail here.

The difficulty is over. The codes of difficult parts are as follows:

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. Finally, hide the brush and keep the window displayed.

ht()
done()

Final code:

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()

Difficulty: ※ x2 5 

5, Sixteenth note

effect:

Code explanation:

1. Import module

from turtle import *

 2. According to the code for drawing octaves, make some changes on this basis. For details, see the notes in the code:

pensize(6)
begin_fill()
circle(40,450)
end_fill()
fd(180)
right(75)
fd(180)
right(105)
fd(30) # Move 30 pixels first
p=pos() # Obtain the position coordinates. Later, you can draw a line segment with more 16 diaeresis than 8 diaeresis
fd(150) # Move another 150 pixels to fill 180 pixels
begin_fill()
circle(-40)
end_fill()

3. Move to the position of variable p and draw the extra line segments.

pu()
goto(p)
pd()
right(75)
fd(180)

4. Hide the brush and keep the window displayed

ht()
done()

Final code:

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()

Difficulty: ※ x1 25 

6, A sixteenth note

effect:

Code explanation:

1. Import module

from turtle import *

 2. set a property

pensize(6)

3. Draw a circle

begin_fill()
circle(40,450)
end_fill()

 4. Draw segments and obtain coordinates

fd(140)
p=pos()
fd(40)
right(180)

5. Draw an arc

circle(80,40)
circle(-80,45)

 6. Draw the second curve

pu()
goto(p)
pd()
seth(-90)

circle(80,40)
circle(-80,45)

7. Hide the brush and keep the window displayed

ht()
done()

Final code:

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()

Difficulty: ※ x1 twenty-five

7, Octant rest

effect:

Code explanation

1. Import module

from turtle import *

 2. set a property

pensize(6)

3. Draw a circle

begin_fill()
circle(20)
end_fill()

4. Draw arc

circle(90,40)

 5. Draw line segments

seth(-115)
fd(120)

6. Hide the brush and keep the window displayed

ht()
done()

Final code:

from turtle import *

pensize(6)

begin_fill()
circle(20)
end_fill()

circle(90,40)
seth(-115)
fd(120)

ht()
done()

Difficulty: ※ x1

8, Dichotomy rest

effect:

Code explanation:

1. Import module

from turtle import *

 2. set a property

pensize(6)

3. Draw the line segment on the left of the rectangle

fd(30)

 4. Draw a rectangle

begin_fill()
for i in range(2):
    fd(90)
    left(90)
    fd(10)
    left(90)
end_fill()

5. Move to the lower right corner of the rectangle

fd(90)

 6. Draw the line segment to the right of the rectangle

fd(30)

7. Hide the brush and keep the window displayed

ht()
done()

Final code:

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()

Difficulty: ※ x1 25 

Extension: full stop

effect:

The code is similar to the binary rest. On this basis, modify the left in the loop to right. The code is as follows:

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()

Difficulty: ※ x1 twenty-five

9, Sixteen minute rest

effect:

Code explanation:

1. Import module

from turtle import *

2. Set properties

pensize(6)

 3. Draw a circle

begin_fill()
circle(20)
end_fill()

4. Draw arcs and segments

circle(90,40)
h=heading()
seth(-115)
fd(80)
p=pos()

 5. Draw an arc

seth(h)
circle(90,-40)

6. Draw a circle

begin_fill()
circle(20)
end_fill()

 7. Set the end point of the previous segment as the start point and continue to draw the segment

pu()
goto(p)
pd()

seth(-115)
fd(80)

8. Hide the brush and keep the window displayed

ht()
done()

Final code:

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()

Difficulty: ※ x2

10, Treble clef

effect:

It is composed of multiple arcs and line segments, which will not be explained in detail here. The final code is:

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()

Difficulty: ※ x3

Previous articles:

Python Turtle small project 6_ Lele programmer blog - CSDN blog this time draws a chinchilla with turtle, including detailed explanation of the codehttps://blog.csdn.net/leleprogrammer/article/details/122154025Python Turtle small project 4_ Lele programmer's blog - CSDN blog draws three kinds of fruits with the Tuttle modulehttps://blog.csdn.net/leleprogrammer/article/details/122139346Python Turtle small project 3_leleprogrammer blog - CSDN blog this time, we still use the turtle module for drawing. This teaching draws two patterns (pay attention to the column of turtle drawing and continuously update the drawing teaching articles) 1. Note code teaching: first import the required module import turtle as t, and then initialize the parameter t.color("black")t.pensize(5) of the brush to fill in black t.begin_fill() draw a circle t.left(90)t.circle(25) preceded by a small note, and then stop filling t.end_fill() draw the small stick T. of the first notehttps://blog.csdn.net/leleprogrammer/article/details/122137419Python Turtle small project 2_leleprogrammer's blog CSDN blog uses the turtle module to draw this time. 1. Star effect: code explanation: first import the required module import turtle as timport random, and then set the attribute 1 of the turtle brush Set the speed to maximum 2 Set the background to dark blue 3 Set the brush and fill color to yellow t.speed(0)t.bgcolor("darkblue") # background color t.color("yellow") # color define a star function draw stars def star(): # star function t.penuhttps://blog.csdn.net/leleprogrammer/article/details/121840596python turtle small project_ leleprogrammer blog - CSDN blog_ The Turtle module of python turtle project draws beautiful graphics.https://blog.csdn.net/leleprogrammer/article/details/121434818

It's not easy to make. Remember to praise and pay attention if you like!

Keywords: Python Back-end turtle

Added by victordb on Wed, 19 Jan 2022 06:51:18 +0200