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

How to use python to draw a dedicated Fu

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

Share

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

This article mainly explains "how to use python to draw a dedication to work", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use python to draw a blessing of dedication"!

Introduction to Turtle Brush

Turtle drawing is an interesting module built into Python, which is called turtle and relies on python's built-in tkinter module. It originated from the Logo language in the 1960s and later became a built-in module for Python. Turtle drawing provides some simple drawing methods that allow a "sea turtle" to move back and forth on the screen according to the written control instructions (code), and can draw graphics on its crawling path. Through the drawing of sea turtles, you can not only draw graphics on the screen, but also see the whole drawing process. In addition, the drawing of sea turtles is very friendly to beginners, and it can easily write many interesting examples.

Three elements of sea turtle drawing:

There are three key elements in drawing with sea turtles, namely, direction, position and brush. When drawing sea turtles, the main thing is to control these elements to draw the graphics we want.

Main methods:

Direction: when drawing sea turtles, the direction is mainly used to control the movement direction of the sea turtles.

The left () / lt () method: turn the turtle left (counterclockwise) to specify degrees. The right () / rt () method: turn the turtle right (clockwise) to specify the degree. Setheading () / seth () method: sets the turtle's orientation to 0 (east), 90 (north), 180 (west) or 270 (south)

Position: when drawing sea turtles, the position is mainly used to control the distance the sea turtles move.

Forward (distance) / fd (distance): let the turtle move forward a specified distance. Backward (distance) / bk (distance): let the turtles back a specified distance. Goto (xQuery y): move the turtle to a specific position on the canvas. That is, the location specified by the coordinates (XBI y). Setx (x): sets the Abscissa of the turtle to x, with the ordinate unchanged. Sety (y): sets the ordinate of the turtle to y, with the Abscissa unchanged. Home (): the turtle moves to the initial coordinates (0P0) and sets the orientation to the initial direction.

Brushes: the brushes used in turtles are equivalent to those used in real-life drawings. In turtle drawing, you can control the thickness, color and speed of the lines with a brush.

Pensize () sets the width of the brush (the brush line thickness is the specified size); pencolor () has no parameter and returns the current brush color, which can be a string such as "green", "red", or a rgb color tuple. Speed (speed) sets the speed of brush movement, and the speed range of brush painting is an integer. The larger the number, the faster you draw. " The "Fu" word source code from turtle import * screensize (800jue 600, "red") # sets the canvas size and changes the background to red pensize (50) # Brush size pencolor ('black') # Brush Color shape ("circle") # shape is round speed (3) # Brush Speed, the larger the parameter The faster "" draw the left side of the word "" # paint point seth (- 60) # brush direction (parameter equivalent to degrees) penup () # pick up bk (240) # back seth (- 45) pendown () # drop fd (50) # forward # horizontal seth (45), penup (), bk (135i) seth (15), pendown (), fd (135) # paint skim seth (- 125c), pendown (), fd (200) # Vertical seth (55) Penup (), fd (150) seth (- 90), pendown (), fd (220) # paint points seth (90), penup (), fd (220) seth (- 45), pendown (), fd (60) "" right part of the word "" # draw a seth (70), penup (), fd (190) seth (10), pendown (), fd (120) # paint seth (38), penup (), bk (150) # Vertical seth (- 85) Pendown (), fd (85), penup (), bk (85) # horizontal seth (10), pendown (), fd (120) # horizontal seth (- 95), pendown (), fd (90) # horizontal seth (9), penup (), bk (95), pendown (), fd (95) # Picture seth (38), penup (), bk (165) # Vertical seth (- 85), pendown (), fd (110), penup (), bk (110) # horizontal seth (10) Pendown (), fd () # Vertical seth (- 95), pendown (), fd (145i) # horizontal penup (), bk (85), pensize (30) seth (- 170), fd (150,150,150) # Vertical seth (165,165,165,85,85) seth (- 90), pendown (), fd (90) # horizontal seth (4), penup (), bk (60), pendown (), pensize (50) Fd (120) hideturtle () # Hidden brush turtle shape mainloop () # event loop function of the tkinter module Leaving the curtain open after drawing is equivalent to showing the result of done ().

At this point, I believe you have a deeper understanding of "how to use python to draw a professional blessing". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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