Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python's method of drawing arbitrary graphs using the turtle Library

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "Python uses turtle library to draw any intention". In daily operation, I believe that many people have doubts about the method of Python using turtle library to draw any intention. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "Python uses turtle library to draw any diagram". Next, please follow the editor to study!

Environment configuration

System: Windows10

Version: python 3.8

Turtle Literacy 1. Settings for the drawing form turtle.setup (width, height, startx, starty)

Startx, starty is in the center of the screen by default.

two。 Brush control function turtle.penup () # alias turtle.pu (), lift brush turtle.pendown () # alias turtle.pd (), drop brush turtle.pensize (width) # alias turtle.width (width), brush width turtle.pencolor (color) # color is a color string or rpencil g, b value, brush color

Note:

Color string: turtle.pencolor ("purple")

Decimal value of RGB: turtle.pencolor (0.63,0.13,0.94)

Tuple value of RGB: turtle.pencolor ((0.63, 0.13, 0.94))

3. Shape rendering function turtle.forward (d) # alias turtle.fd (d), straight forward d (can be negative) pixel turtle.circle (r, extent=None) # draw arc turtle.setheading (angle) # alias turtle.seth (angle) of extent angle according to radius r, angle: absolute angle of travel direction turtle.left (angle) # Turtle turn left Angle: the angle of rotation in the turtle's current direction turtle.right (angle) # Turtle turn right turtle.goto (x, y) # absolute coordinates Turtle drawing 1. Classic case import turtle as tt.setup (650650200200) t.speed (10) # brush speed, 1 to 10 increments t.penup () t.fd (- 250) t.pendown () t.pensize (25) t.pencolor ("purple") t.seth (- 40) for i in range (4): t.circle (40,80) t.circle (- 40,80) t.circle (40,80max 2) t.fd (40) t.circle (16) T.fd (40 * 2amp 3) t.mainloop () # keep the interface displayed The following statement fails 2. Draw any picture import turtle as timport cv2t.getscreen (). Colormode (255) img1 = cv2.imread ('2.jpg') [0:-2: 2] # fill in the absolute path of your picture, it is recommended to follow 100kb. Width= len (img1 [0]) height= len (img1) t.setup (width=width / 2 + 100, height=height + 100) t.speed (8) t.pu () t.goto (- width / 4 + 10, height / 2-10) t.pd () t.tracer (2000) for K1, i in enumerate (img1): for j in i [:: 2]: t.pencolor ((j [0], j [1]) J [2]) t.fd (1) t.pu () t.goto (- width / 4 + 10, height / 2-10-K1-1) t.pd () t.done () # keep the interface displayed so far The study on "Python's method of drawing arbitrary drawings using turtle library" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report