How to draw a loving Christmas tree with Python
This article mainly introduces how to use Python to draw a loving Christmas tree, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.
Code
#-*-coding: utf-8-* "Created on Sat Dec 12 12:29:09 2020@author: haoyu"import turtle as timport random# Love function # divides the love into two semicircles and a square # r is the semicircle radius L = 2R is the square side length # adjust the radius to adjust the love size def loving_heart (r): l = 2 * r t.left (45) t.forward (l) t.circle (r180) t.right (90) t.circle (r180) t.forward (l) # Tree function (recursive) def tree (d, s): if d