0 Environment
Python version: 3.6.6
Operating System: Mac OS Mojave 10.14.2
1 Introduction
Lately my daughter-in-law has been checking it on her cell phone every night at dinner and on the toilet as well.
WTF? What are you doing?
Yes, she's watching Team America ......
This man is better looking than me? ......
Richer than me? ......
Or is it more accented than me? ......
The answer is obvious, and I'm sure you all have good eyes.
Then the question arises, as a man, how can one endure? Although it is a star, although it is a fake, although it is already unable to undo the defeat ...... Then I will send you a shield of Team America ......
This article is not Turtle's introductory article, so about the basic use of brushes small fat not to repeat in this article. Leave a comment if you're interested and I'll write a post or a series based on your feedback.
2 Practical combat
Let's look at a rendering first:
Anyone who has used a Turtle knows that the paintbrush is required to lift and drop the hand. This must be understood because the computer is very rigid and every movement you make must be told to him, including the GC.
So once your brush is down, it will leave writing everywhere it passes. If you wish to space out a distance you need to go through "Lift Brush" - > "Move Brush" - > "Drop Brush".
So let's start by encapsulating this action into a function:
def setpen(x, y): # Lift the pen () # Move the brush to (x, y) (x, y) # Putting pen to paper () (0)
The next step is to draw the shield. For the shield, notice the Team America shield, the colors are "red" - > "white" - > "red" - > "blue".
One trick here is that the background color of the circle filled in later is able to override the background color of the circle drawn earlier.
def circle(x, y, r, color): # To make sure we draw a circle that is round enough, we set the sides of the circle to have more sides n = 36 angle = 360 / n pi = 3.1415926 # Circumference c = 2 * pi * r # Length of each edge l = c / n # Starting position start_x = x - l / 2 start_y = y + r # Move the brush setpen(start_x, start_y) # Select brush color (color) # Select background color (color) # Filling t.begin_fill() for i in range(n): (l) (angle) t.end_fill()
The next step is to draw that white pentagram inside, and I won't comment on it here because it's pretty much the same process as drawing the circle.
def five_star(l): setpen(0, 0) (162) (150) (0) ('WhiteSmoke') t.begin_fill() () () for i in range(5): (l) (144) t.end_fill()
Main function:
def sheild(): circle(0, 0, 300, 'red') circle(0, 0, 250, 'white') circle(0, 0, 200, 'red') circle(0, 0, 150, 'blue') five_star(284) if __name__ == '__main__': sheild() # End the turtle chart ()
The above is a small introduction to the practice of drawing a Team USA shield with Python detailed integration, I hope to help you, if you have any questions please leave me a message, I will reply to you in a timely manner. Here also thank you very much for your support of my website!