I’ve been looking at some nice ones drawn in Python (mostly turtle), so I’ve sorted them out and picked out some that I think are good ones to share with you (I’ve tested them all and they do work)

Dynamic generation of cherry blossoms

Renderings (this is dynamic) :

The implementation code

Import turtle as T import random import time def Tree(branch, T): time.sleep(0.0005) if branch > 3: If 8 <= branch <= 12: if random. Randint (0, 2) == 0: t.color('snow') # white else: Elif branch < 8: if random. Randint (0, 1) == 0: t.color('snow') else: t.color('lightcoral') T.color ('lightcoral') # lightcoral t.pensize(branch / 2) else: A = 1.5 * random. Random () t.right(20 * a) b = 1.5 * random. Random () Tree(branch -10 * b, t) t.ft (40 * a) Tree(branch -10 * b, T) t.petal (20 * a) t.buckward (branch) t.down() # Def Petal(m, t): Petal(m, t): Petal(m, t) a = 200 - 400 * random.random() b = 10 - 20 * random.random() t.up() t.forward(b) t.left(90) t.forward(a) t.down() T.collar ('lightcoral') # lightcoral t.circle(1) t.pu () t.buckward (a) t.light (90) t.buckward (b) # drawing area t = t.tle () # canvas size w = T.creen () t.Heideturtle () # Hide the paintbrush t.getscreen().tracer(5, 0) w.creensize (bg='wheat') # Wheat wheat t.ft (90) t.p () t.buckward (150) t.town () t.Color ('sienna') # Paint cherry Tree trunk (60, T) # Petal(200, t) w.exitonclick()Copy the code

Effect of falling

Effect:

Code:

from turtle import * from random import * from math import * def tree(n,l): T = cos(radians(fadein ()+45))/8+0.25 pencolor(t,t,t) pensize(n/3) forward(l)# draw tree if n>0: C = random()*0.25+0.7 d = l*(random()*0.25+0.7) Tree (n-1,d) # left(b+c) tree(n-1, D) # right(c) else: Radians (heading()-45))/4+0.5 pencolor(n,n*0.8,n*0.8) circle(3) left(90) # If (random () > 0.7) : Pu () # falling t = heading() an = -40 +random()*40 setheading(an) dis = int(800*random()*0.5 + 400*random()*0.3 + 200*random()*0.2) forward(dis) setheading(t) # draw leaf pd() right(90) n = cos(radians(heading()-45))/4+0.5 Pencolor (n*0.5+0.5,0.4+n*0.4,0.4+n*0.4) circle(2) left(90) pu() # return t=heading() setheading(an) backward(dis) Setheading (t) PU () Backward (l)# BgColor (0.5,0.5,0.5)# Background color HT ()# Hidden Turtle Speed (0)# Speed 1-10 increments, 0 fastest tracer(0,0) pu()# backward(100) left(90)# left(90)# backward(300)# back 300 tree(12,100)# recursion 7 layer done()Copy the code

The dark effect

Effect:

code

from turtle import * from random import * from math import * def tree(n, l): Pd () t = cos(radians(heading() + 45)) / 8 + 0.25 pencolor(t, t, t) pensize(n / 4) forward(l) if n > 0: B = random() * 15 + 10 C = random() * 15 + 10 D = l * (random() * 0.35 + 0.6) tree(n-1, d) left(b + c) tree(n - 1, d) right(c) else: Right (90) n = cos(radians(heading() -45)) / 4 + 0.5 pencolor(n, n, n) circle(2) left(90) pu() backward(l) bgcolor(0.5, 0.5, 0.5) HT () Speed (0) tracer(0, 0) left(90) PU () backward(300) tree(13, 100) done()Copy the code

Two roses

Effects (with drawing process)

code

From turtle import * import time setup(1000,800,0,0) speed(0) penup() Seth (90) fd(340) Seth (0) pendown() speed(5) Begin_fill () fillcolor('red') circle(50,30) for I in range(10): fd(1) left(10) circle(40,40) for I in range(6): Fd (1) left(3) circle(80,40) for I in range(20): fd(0.5) left(5) circle(80,45) for I in range(10): Fd (2) left(1) circle(80,25) for I in range(20): Fd (1) left(4) circle(50,50) time.sleep(0.1) circle(120,55) speed(0) Seth (-90) fd(70) right(150) fd(20) left(140) Circle (140,90) left(30) circle(160,100) left(130) fd(25) penup() right(150) circle(40,80) pendown() left(115) fd(60) Penup () left(180) fd(60) pendown() end_fill() right(120) circle(-50,50) circle(-20,90) speed(1) fd(75) speed(0) Circle (90,110) penup() left(162) fd(185) left(170) pendown() circle(200,10) circle(100,40) circle(-52,115) left(20) Circle (100,20) circle(300,20) speed(1) fd(250) penup() speed(0) left(180) fd(250) circle(-300,7) right(80) circle(200,5) Pendown () left(60) begin_fill() fillcolor('green') circle(-80,100) right(90) fd(10) left(20) circle(-63,127) end_fill() Penup () left(50) fd(20) left(180) pendown() circle(200,25) penup() right(150) fd(180) right(40) pendown() begin_fill() Fillcolor ('green') circle(-100,80) right(150) fd(10) left(60) circle(-80,98) end_fill() penup() left(60) fd(13) Left (180) pendown() speed(1) circle(-200,23) exitonclick()Copy the code

Three Christmas tree

Christmas Tree (Dynamic Generation effect)

Code:

From Turtle import * import random import time n = 100.0 speed("fastest") screensize(bg='seashell') left(90) forward(3*n) color("orange", "yellow") begin_fill() left(126) for i in range(5): Forward (n/5) right(144) forward(n/5) left(72) end_fill() right(126) color("dark green") backward(n*4.8) def tree(d, s): if d <= 0: return forward(s) tree(d-1, s*.8) right(120) tree(d-3, s*.5) right(120) tree(d-3, s*.5) right(120) backward(s) tree(15, n) backward(n/2) for i in range(200): a = 200 - 400 * random.random() b = 10 - 20 * random.random() up() forward(b) left(90) forward(a) down() if random.randint(0, 1) == 0: color('tomato') else: color('wheat') circle(2) up() backward(a) right(90) backward(b) time.sleep(60)Copy the code

To be continued!