1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#
# Code under the MIT license by Alexander Pruss
#
from mcturtle import *
import random
def tree(depth,thickness,branchLen):
if depth <= 0:
return
if random.random() < 0.2:
return
if branchLen < 4:
t.penblock(LEAVES_OAK_PERMANENT)
else:
t.penblock(WOOD)
t.penwidth(thickness)
t.go(branchLen)
newThickness = thickness / 2
if newThickness < 1:
newThickness = 1
newBranchLen = branchLen * 0.75
if branchLen < 1:
branchLen = 1
for i in range(4):
t.pitch(30)
tree(depth-1,newThickness,newBranchLen)
t.pitch(-30)
t.roll(90)
t.penup()
t.back(branchLen)
t.pendown()
t = Turtle()
t.turtle(None)
t.pendelay(0)
t.penup()
t.go(10)
t.verticalangle(90)
t.pendown()
tree(8,8,20)
|