from turtle import * def tree(n): tree2(n, 0, 0, 2**n) # bez kresleni vrcholu def tree2(n, x, y, width): # trivialni pripady if(n == 0 or n == 1): return # strom nejmensi hloubky (hloubky 2) s rameny if(n == 2): pu() goto(x, y) pd() goto(x+width/4, y-20) pu() goto(x, y) pd() goto(x-width/4, y-20) pu() # vetsi stromy vyresime rekurzi else: tree2(2, x, y, width) tree2(n-1, x-width/4, y-20, width/2) tree2(n-1, x+width/4, y-20, width/2) # vcetne kresleni vrcholu def tree3(n, x, y, width): if(n == 0): return if(n == 1): pd() circle(3) pu() return if(n == 2): pu() goto(x, y) pd() circle(3) goto(x+width/4, y-20) circle(3) pu() goto(x, y) pd() goto(x-width/4, y-20) circle(3) pu() else: tree3(2, x, y, width) tree3(n-1, x-width/4, y-20, width/2) tree3(n-1, x+width/4, y-20, width/2)