Tree Function
by G.G.Otto, Apr 6, 2020, 12:22 AM
I made a python function that draw a tree. It's really funny to put into scripts that do random things with turtle.
Code
I made a code that randomly draws stuff. It's really fun to watch, and especially funny when it randomly draws a tree. I can't post it here because it's too long.
Code
import turtle def tree(t,n,x,y): if n < 0: print('Error: n out of range') return if n%1 != 0: print('Error: n not integer') return length = 10+2.5*n lengthT = n*1.5+10 tt = n+4 ttt = n/2+5 t.pu() t.goto(x,y) t.color('brown') t.pensize(tt) t.setheading(90) t.pd() t.fd(lengthT) t.color('green') t.left(135) t.pensize(ttt) if n >= 1: for i in range(n-1): t.fd(length) t.bk(length) t.left(90) t.fd(length) t.bk(length) t.left(135) t.fd(ttt) t.right(225) length -= 2.5 if n > 0: t.fd(length) t.bk(length) t.left(90) t.fd(length) tree(turtle.Turtle(),10,30,30)
I made a code that randomly draws stuff. It's really fun to watch, and especially funny when it randomly draws a tree. I can't post it here because it's too long.