In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you how to use python to draw pictures, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Yesterday we wrote how to use python to draw arcs or circles. Today we draw all kinds of flowers on the basis of yesterday.
First of all, we try to add a recursive rotation angle on the basis of the arc:
Import turtle
Import math
Bob = turtle.Turtle ()
# create a turtle object named bob
Print (bob)
# draw this object
Def arc (trecom r.angle):
Arc_length = 2 * math.pi * r * angle / 360
# find the arc length
N = 50
# the number of times to draw a straight line
The higher the number of # n, the better, but the running time will increase (you can also use arc length directly)
Step_length = arc_length/n
# the length of each line drawn
Step_angle = angle/n
# the angle changed each time the line is drawn
For i in range (n):
T.fd (step_length)
# draw a straight line forward
T.lt (step_angle)
# turn the angle
T.lt (120)
# turn 120 degrees after drawing an arc
Arc (bob,200120)
# Recursive statement
Turtle.mainloop ()
# preserve graphics
Arc (bob,200,60)
# call function to realize real-time rendering
This is the clover realized by recursion.
In fact, as long as we change a small parameter, we can become such a beautiful flower. Have you guessed which step it is?
In fact, t.lt (120) becomes t.lt (90), and it automatically goes on as soon as the angle changes.
Change two parameters a little more, and it will take a handle. Hey.
If you pay attention, you will find that the flowers are all round in the middle. Which code caused this?
Python's turtle library is not so attractive, you can also use it to draw trademarks:
And beautiful snowflakes! (Koch curve, let's realize this tomorrow.)
On how to use python drawing to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.