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 draw a beautiful and interesting flower with python's little turtle Turtle

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how to use python's little turtle Turtle to draw a beautiful and interesting flower. The editor thinks it is very practical, so I share it with you. I hope you can learn something after reading this article.

In 1967, Daniel G. Bobrow, Wally Feurzeig, Seymour Papert and Cynthia Solomon designed the LOGO programming language to teach children programming in an intuitive way. Although the language can also solve complex problems, what impresses you most is its turtle mapping system (Turtle Graphics).

The turtle module has been built into the Python environment, and you only need to enter 2 lines of statements in Python IDLE to get the baby turtle in place.

Turtleturtle.reset ()

We use turtle to draw an interesting flower.

Import turtle# introduces turtle from the standard library

Def draw_diamond (turt):

For i in range (1pr 3):

Turt.forward (100) # take 100 steps forward

Turt.right (45) # then the turtle turns 45 degrees to the right

Turt.forward (100) # take 100 steps forward

Turt.right (135) # and then turn right by 135o

Def draw_art ():

Window = turtle.Screen () # get a window handle

Window.bgcolor ("blue") # sets the background blue

# create an instance of Turtle

Brad = turtle.Turtle ()

Brad.shape ("turtle") # shape is a sea turtle

Brad.color ("red") # Color is red

Brad.speed ('fast') # the speed of drawing is fast fast slow slow

For i in range (1mem37): # cycle 36 times

Draw_diamond (brad) # draw a diamond as a petal

Brad.right (10) # rotated 10 degrees

Brad.right (90) # A week after painting, the turtle turns 90 degrees

Brad.forward (260) # draw a long line

Window.exitonclick () # the window closes automatically when clicked

Draw_art () # call function

Effect:

(some text source network, only learn to record the use. )

The above is how to use python's little turtle Turtle to draw a beautiful and interesting flower. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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: 237

*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