from turtle import * MAX_LEG_LENGTH = 50 def get_input_with_default(question, default): i = raw_input(question + " (default='" + str(default) + "'): ") if not i: i = default return i def updaterule(s): return s.replace(production_rule[0], production_rule[1]) def exec_command(l, step_size = 10): if l == "F": forward(step_size) elif l == "+": left(angle) elif l == "-": right(angle) def showrule(s, step_size = 10): clear() speed('fastest') color("blue") up() goto(0,0) setheading(0) down() for l in s: exec_command(l, step_size) start_string_default = "F" production_rule_default = "F->F+F--F+F" start_string = get_input_with_default("Start string", start_string_default) production_rule_pair = get_input_with_default("Production rule", production_rule_default) production_rule = production_rule_pair.split("->") angle = int(get_input_with_default("Angle", 60)) width_ratio = 1.0/3.0 current_string = start_string for i in range(0, 6): current_string = updaterule(current_string) showrule(current_string, MAX_LEG_LENGTH * (width_ratio ** i)) # raw_input("Generation done, press any key to continue")