Get the App
SLTechnology News&Howtos  ›  Development  › 

How to draw a Christmas tree using Python

Shulou Source: shulou.com Published: 2022-06-02 05:42:32 10月04日 Update

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

Tags: Color size snowflake method colorful lights that is five-pointed star effect brush angle pentagonal Christmas tree content coordinates font more branches white pen this is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MariaDB Shulou Tech Info Microsoft Linux