from turtle import Turtle from random import randint def rev(string): if len(string) == 0: return string else: return string[-1] + rev(string[:-1]) #print(rev("")) # Vypise premistovani kotoucu pri reseni Hanojskych vezi. # - n: pocet kotoucu # - source: tyc, na ktere jsou kotouce na zacatku # - target: tyc, na kterou chceme kotouce premistit # - auxiliary: pomocna tyc, kterou lze vyuzit v prubehu premistovani def hanoi(n, source, target, auxiliary): if n == 1: print(source + " -> " + target) else: hanoi(n-1, source, auxiliary, target) hanoi(1, source, target, auxiliary) hanoi(n-1, auxiliary, target, source) #hanoi(3, 'A', 'C', 'B') t = Turtle() t.speed(10) MIN_LEN = 8 # length: delka kmenove cary def tree(length): if length > 10: newLen = 2*length//3 angle = 45 newLen = length - randint(MIN_LEN//2, length//2) angle = randint(26, 48) t.forward(length) t.left(angle) tree(newLen) t.left(90) tree(newLen) t.left(90-angle) t.forward(length) #t.left(90) #tree(100) def snowflake2(d, l): koch(d, l) t.right(60) koch(d, l) t.right(60) koch(d, l) t.right(60) koch(d, l) t.right(60) koch(d, l) t.right(60) koch(d, l) def snowflake(d, l): koch(d, l) t.right(120) koch(d, l) t.right(120) koch(d, l) def koch(d, l): if d == 0: t.forward(l) else: koch(d - 1, l // 3) t.left(60) koch(d - 1, l // 3) t.right(120) koch(d - 1, l // 3) t.left(60) koch(d - 1, l // 3) snowflake(3, 180) #snowflake2(2, 60)