Back to index

python3.2  3.2.2
Functions | Variables
turtledemo.lindenmayer Namespace Reference

Functions

def replace
def draw
def main

Variables

tuple msg = main()

Function Documentation

def turtledemo.lindenmayer.draw (   commands,
  rules 
)

Definition at line 38 of file lindenmayer.py.

00038 
00039 def draw( commands, rules ):
00040     for b in commands:
00041         try:
00042             rules[b]()
00043         except TypeError:
00044             try:
00045                 draw(rules[b], rules)
00046             except:
00047                 pass
00048 

Here is the caller graph for this function:

Definition at line 49 of file lindenmayer.py.

00049 
00050 def main():
00051     ################################
00052     # Example 1: Snake kolam
00053     ################################
00054 
00055 
00056     def r():
00057         right(45)
00058 
00059     def l():
00060         left(45)
00061 
00062     def f():
00063         forward(7.5)
00064 
00065     snake_rules = {"-":r, "+":l, "f":f, "b":"f+f+f--f--f+f+f"}
00066     snake_replacementRules = {"b": "b+f+b--f--b+f+b"}
00067     snake_start = "b--f--b--f"
00068 
00069     drawing = replace(snake_start, snake_replacementRules, 3)
00070 
00071     reset()
00072     speed(3)
00073     tracer(1,0)
00074     ht()
00075     up()
00076     backward(195)
00077     down()
00078     draw(drawing, snake_rules)
00079 
00080     from time import sleep
00081     sleep(3)
00082 
00083     ################################
00084     # Example 2: Anklets of Krishna
00085     ################################
00086 
00087     def A():
00088         color("red")
00089         circle(10,90)
00090 
00091     def B():
00092         from math import sqrt
00093         color("black")
00094         l = 5/sqrt(2)
00095         forward(l)
00096         circle(l, 270)
00097         forward(l)
00098 
00099     def F():
00100         color("green")
00101         forward(10)
00102 
00103     krishna_rules = {"a":A, "b":B, "f":F}
00104     krishna_replacementRules = {"a" : "afbfa", "b" : "afbfbfbfa" }
00105     krishna_start = "fbfbfbfb"
00106 
00107     reset()
00108     speed(0)
00109     tracer(3,0)
00110     ht()
00111     left(45)
00112     drawing = replace(krishna_start, krishna_replacementRules, 3)
00113     draw(drawing, krishna_rules)
00114     tracer(1)
00115     return "Done!"

Here is the call graph for this function:

def turtledemo.lindenmayer.replace (   seq,
  replacementRules,
  n 
)

Definition at line 30 of file lindenmayer.py.

00030 
00031 def replace( seq, replacementRules, n ):
00032     for i in range(n):
00033         newseq = ""
00034         for element in seq:
00035             newseq = newseq + replacementRules.get(element,element)
00036         seq = newseq
00037     return seq

Here is the caller graph for this function:


Variable Documentation

Definition at line 117 of file lindenmayer.py.