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 polygonal stars with Python

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you "Python how to draw polygonal stars", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Python how to draw polygonal stars" this article.

I. introduction

After having a certain Python programming foundation, we can combine for cycle to write polyhedral stars, as long as a few simple loops can greatly solve the problem of repeatedly writing the same code, the following editor will take triangular stars and pentagonal stars as examples, and then introduce how to draw polyhedral stars.

2. Methods

Preliminary knowledge:

Command description pensize (width) set brush width turtle.forward (distance) move distance pixel length turtle.color (color1,color2) while setting pencolor,fillcolorturtle.right (degree) to move degree °turtle.left (degree) counterclockwise move degree °turtle.begin _ fill () ready to start filling figure turtle.end_fill () fill completed 3. Experimental results and discussion 1. Triangle drawing # introduces the turtle library import turtle# to set the background color and fill color turtle.color ("yellow") for triangles "blue") # ready to start filling graphics turtle.begin_fill () For i in range (3): # number of sides required to write in parentheses # move 300pixel length turtle.forward (300) # counterclockwise move 120degrees turtle.left (120) # fill completed turtle.end_fill () # pycharm need this statement to ensure that the drawing does not end running turtle.done ()

After successfully drawing the triangle, we begin to try to further increase the number of angles. it should be noted that the degree of the rotation angle is very important when drawing the pentagram. The following take the standard pentagram as an example, using the same for experiment is simple and fast.

two。 Drawing of pentagram import turtleturtle.pensize (10) turtle.color ("red", "yellow") turtle.begin_fill () for i in range (5): # 5 represents a pentagram with a side length of 5 turtle.forward (300) turtle.left (144C) # the outer corner of a regular polygon is a fixed turtle.end_fill () turtle.done ()

3. Drawing of polyhedral stars import turtleturtle.pensize (10) turtle.color ("red", "yellow") turtle.begin_fill () for i in range (9): # there are 9 sides turtle.forward (80) turtle.left (40) turtle.end_fill () turtle.done ()

These are all the contents of the article "how to draw polygonal stars with Python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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: 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