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 Python draws Rose and Page

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article will explain in detail how Python draws roses and Page. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1 introduction to turtle Library

Turtle library is a very popular function library for drawing images in Python language. imagine a small tortoise starting at the origin of a coordinate system with a horizontal axis of x and a vertical axis of y.

It moves in this plane coordinate system according to the control of a set of function instructions, thus drawing a figure on its crawling path.

2 brushes

On the canvas, by default, there is a coordinate origin that is the coordinate axis of the center of the canvas, and there is a small turtle facing in the positive direction of the x axis on the coordinate origin. Here we use two words to describe the little tortoise: the coordinate origin (position), facing the positive direction of the x-axis (direction), and in turtle drawing, the position direction is used to describe the state of the little tortoise (brush).

Brush (properties of the brush, color, width of lines, etc.)

Turtle.pensize (): sets the width of the brush

Turtle.pencolor (): no parameter is passed, the current brush color is returned, and the parameter is passed to set the brush color, which can be a string such as "green", "red", or a RGB 3 tuple.

Urtle.speed (speed): sets the speed of brush movement. The speed range of brush painting is an integer. The larger the number, the faster the number.

3 drawing command

There are many commands to manipulate tortoise drawing, which can be divided into three types: one is motion command, one is brush control command, and the other is global control command.

Explain several commonly used motion commands:

Forward (100): move 100 pixels in the current brush direction

Right (90): move 90 degrees clockwise

Left (90): move 90 degrees counterclockwise

Goto (XBI y): move to XBI y

Circle (), dot (): draw circles and dots, respectively

Brushes and global commands:

Fillcolor (colorstring): fill color for drawing a graph

Clear (): clear the turtle window

4 examples

1 draw quadrilateral

2 draw a cross

3 sunflowers

4 roses

5 Piglet Paige

This is the end of the article on "how to draw roses and Page in Python". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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

Internet Technology

Wechat

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

12
Report