How to draw a Christmas tree with Python
This article mainly explains "how to draw a Christmas tree with Python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to draw a Christmas tree with Python.
The simplest:
Height = 5stars = 1for i in range (height): print (('* (height-I)) + ('* * stars)) stars + = 2print (('* height) +'|')
Effect:
Ha, there is always a feeling of deceiving everyone.
In fact, this article is to introduce the Turtle library to draw Christmas trees.
Import turtlescreen = turtle.Screen () screen.setup (375,700) circle = turtle.Turtle () circle.shape ('circle') circle.color (' red') circle.speed ('fastest') circle.up () square = turtle.Turtle () square.shape (' square') square.color ('green') square.speed (' fastest') square.up () circle.goto (0280) circle.stamp () k = 0for i in range (1) 13): y = 30 * i for j in range (I-k): X = 30 * j square.goto (x,-y + 280) square.stamp () square.goto (- x,-y + 280) square.stamp () if I% 4 = 0: X = 30 * (j + 1) circle.color ('red') circle.goto (- x -y + 280) circle.stamp () circle.goto (x,-y + 280) circle.stamp () k + = 3 if I% 4 = 3: X = 30 * (j + 1) circle.color ('yellow') circle.goto (- x,-y + 280) circle.stamp () circle.goto (x -y + 280) circle.stamp () square.color ('brown') for i in range (13,17): y = 30 * i for j in range (2): X = 30 * j square.goto (x,-y + 280) square.stamp () square.goto (- x,-y + 280) square.stamp ()
Method 2:
Import turtle# defines the green leaf function def tree (d, s): if d of the Christmas tree