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 Christmas tree using Python

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

Share

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

How to use Python to draw a Christmas tree, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

T.pensize (10) # modify brush size

Effect picture:

①, this is the effect of t.pensize (10).

②, this is the effect of t.pensize (5).

Full version of the code:

Import turtle ast # as is an alias. The subsequent calls are all turtlefrom turtle import * import random as rimport time n = 100.0t.pensize (10) # modify the brush size speed ("fastest") # define screensize (bg='black') # define the background color, you can change your own color left (90) forward (3 * n) color ("orange", "yellow") # define the color of the top star, and the outer circle is orange Inside is yellowbegin_fill () left (126) for i in range (5): # draw pentagram forward (n / 5) right (144C) # Angle of pentagram forward (n / 5) left (72) # continue to change angle end_fill () right (126) def drawlight (): # define the method of drawing colored lights if r.randint (0,30) = 0: # if you think there are too many colored lights We can enlarge the range of values. The corresponding lights will be less color ('tomato') # define the first color circle (6) # define the color lamp size elif r.randint (0 30) = 1: color ('orange') # define the second color circle (3) # define the size of the color lamp else: linewidth = 5 color (' dark green') # draw empty branches in the case of the rest of the random numbers color ("dark green") # define the color of the branches backward (n * 4.8d, s): # start drawing the tree if d

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