current position:Home>Python uses turtle to express white
Python uses turtle to express white
2022-01-30 06:07:29 【Ice and wind all over the sky】
turtle yes python My own drawing library , Generally, you can do some simple drawing effects , The advantage is that it will play the drawn animation , So you can simply create some animation effects , This time draw two hearts and make a confession program , Let's see the final effect first
Here is the main code
First draw a love
A love code is relatively simple , We use two arcs , Two straight lines can draw a simple love
import turtle as t
t.speed(1)
t.pencolor('gray') # Set brush color
t.fillcolor('red') # Set fill color
t.begin_fill()
t.left(40) # Turn left 40 degree
t.forward(100) # Right forward 100 Pixels
t.circle(50, 210) # Draw an arc
t.right(138) # turn right 138 degree
t.circle(50, 210) # Draw an arc
t.forward(100) # forward 100 Pixel
t.end_fill() # Fill color
t.done() # End of all drawing processes
Copy code
For the sake of understanding , The diagram corresponds to the code
there t.speed(1) It controls the speed of drawing , If you want to be slower, you can adjust a larger value , If it is set to 0 Is the fastest (ps: If you don't have to look at the drawing track, you can use tracer Function to achieve faster results )
Draw two hearts
Because there are two loves , We'd better turn the code of drawing love into a draw_heart function , Let's not write duplicate code twice
import turtle as t
t.speed(1)
t.pencolor('gray') # Set brush color
t.fillcolor('red') # Set fill color
# Draw love function
def draw_heart():
t.begin_fill()
t.left(40) # Turn left 40 degree
t.forward(100) # Right forward 100 Pixels
t.circle(50, 210) # Draw an arc
t.right(138) # turn right 138 degree
t.circle(50, 210) # Draw an arc
t.forward(100) # forward 100 Pixel
t.end_fill() # Fill color
# Draw love at the bottom left
t.penup()
t.goto(-80,-80) # The starting point of love at the bottom left
t.pendown()
draw_heart()
# Draw love on the top right
t.penup()
t.goto(0,0) # The starting point of love on the upper right
t.pendown()
t.left(40)
draw_heart()
t.done() # End of all drawing processes
Copy code
Draw arrow
We saw the arrow coming from the upper right corner , Every time you insert a love, there will be some shelter , Here we use penup、pendown Function can solve this scenario well penup --- Bring up the brush , The following movement will not show graphics pendown --- Put down the paintbrush , The following movement will show the figure
Look at the line segment on the graph corresponding to the code
Two in the code penup After that t.forward(68) Is the line segment of the two love shielding parts
Add text
You can draw words with write Functions can be implemented , Relatively simple , Just one more step here , After drawing, let the arrow icon return to the head of the arrow , Finally, paste the completed code
import turtle as t
t.speed(1)
t.pencolor('gray') # Set brush color
t.fillcolor('red') # Set fill color
# Draw love function
def draw_heart():
t.begin_fill()
t.left(40) # Turn left 40 degree
t.forward(100) # Right forward 100 Pixels
t.circle(50, 210) # Draw an arc
t.right(138) # turn right 138 degree
t.circle(50, 210) # Draw an arc
t.forward(100) # forward 100 Pixel
t.end_fill() # Fill color
# Draw love at the bottom left
t.penup()
t.goto(-80,-80) # The starting point of love at the bottom left
t.pendown()
draw_heart()
# Draw love on the top right
t.penup()
t.goto(0,0) # The starting point of love on the upper right
t.pendown()
t.left(40)
draw_heart()
# Draw an arrow
t.pensize(4)
t.penup()
t.goto(100,180) # Move to the upper right corner of the arrow
t.pendown()
t.setheading(225) # Specify the direction of motion
t.forward(140) # Forward 140 Pixels
t.penup()
t.forward(68)
t.pendown()
t.forward(42)
t.penup()
t.forward(68)
t.pendown()
t.forward(60)
t.penup()
t.goto(-100, -150)
t.pencolor('red')
t.write(" Here you know ~", True, font=(" Song style ", 18))
t.goto(-170,-90)
t.pendown()
t.done() # End of all drawing processes
Copy code
copyright notice
author[Ice and wind all over the sky],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201300607256258.html
The sidebar is recommended
- Python collects and monitors system data -- psutil
- Python chat room (Tkinter writing interface, streaming, socket to realize private chat, group chat, check chat records, Mysql to store data)
- Learning this Python library can reduce at least 100 lines of code
- leetcode 67. Add Binary(python)
- Regular re parameter replacement of Python 3 interface automation test framework
- V. pandas based on Python
- Only 15 lines of code is needed for face detection! (using Python and openCV)
- [Python crawler Sao operation] you can crawl Sirius cinema movies without paying
- leetcode 69. Sqrt(x)(python)
- Teach you to read the source code of Cpython (I)
guess what you like
-
Snowball learning started in the fourth quarter of Python. One needs three meals. I have a new understanding of Python functional programming, process-oriented, object-oriented and functional
-
leetcode 88. Merge Sorted Array(python)
-
Don't you know more about a python library before the end of 2021?
-
Python crawler web page parsing artifact XPath quick start teaching!!!
-
Use Python and OpenCV to watermark the image
-
String and related methods of Python data type introduction
-
Heapq module of Python module
-
Introduction to beautiful soup of Python crawler weapon, detailed explanation, actual combat summary!!!
-
Event loop of Python collaboration series
-
Django docking pin login system
Random recommended
- [recalling the 1970s] using Python to repair the wonderful memories of parents' generation, black-and-white photos become color photos
- You used to know Python advanced
- Pyinstaller package Python project
- 2021 IEEE programming language rankings: Python tops the list!
- Implementation of Python automatic test control
- Python advanced: [Baidu translation reverse] graphic and video teaching!!!
- Do you know the fuzzy semantics in Python syntax?
- [Python from introduction to mastery] (XXVII) learn more about pilot!
- Playing excel office automation with Python
- Some applications of heapq module of Python module
- Python and go languages are so popular, which is more suitable for you?
- Python practical skills task segmentation
- Python simulated Login, numpy module, python simulated epidemic spread
- Python opencv contour discovery function based on image edge extraction
- Application of Hoff circle detection in Python opencv
- Python reptile test ox knife (I)
- Day 1: learn the Django framework of Python development
- django -- minio_ S3 file storage service
- [algorithm learning] 02.03 Delete intermediate nodes (Java / C / C + + / Python / go)
- Similarities and differences of five pandas combinatorial functions
- Learning in Python + opencv -- extracting corners
- Python beginner's eighth day ()
- Necessary knowledge of Python: take you to learn regular expressions from zero
- Get your girlfriend's chat records with Python and solve the paranoia with one move
- My new book "Python 3 web crawler development practice (Second Edition)" has been recommended by the father of Python!
- From zero to familiarity, it will take you to master the use of Python len() function
- Python type hint type annotation guide
- leetcode 108. Convert Sorted Array to Binary Search Tree(python)
- For the geometric transformation of Python OpenCV image, let's first talk about the extraordinary resize function
- leetcode 701. Insert into a Binary Search Tree (python)
- For another 3 days, I sorted out 80 Python datetime examples, which must be collected!
- Python crawler actual combat | using multithreading to crawl lol HD Wallpaper
- Complete a python game in 28 minutes, "customer service play over the president card"
- The universal Python praise machine (commonly known as the brushing machine) in the whole network. Do you want to know the principle? After reading this article, you can write one yourself
- How does Python compare file differences between two paths
- Common OS operations for Python
- [Python data structure series] linear table - explanation of knowledge points + code implementation
- How Python parses web pages using BS4
- How do Python Network requests pass parameters
- Python core programming - decorator