<s> from l_system import LSystem <EOL> class PenroseSnowflakeLSystem ( LSystem ) : <EOL> def __init__ ( self ) : <EOL> self . axiom = "<STR_LIT>" <EOL> self . rule = "<STR_LIT>" <EOL> self . steps = <NUM_LIT:0> <EOL> self . ruleF = "<STR_LIT>" <EOL> self . startLength = <NUM_LIT> <EOL> self . theta = radians ( <NUM_LIT> ) <EOL> self . reset ( ) <EOL> def useRule ( self , r_ ) : <EOL> self . rule = r_ <EOL> def useAxiom ( self , a_ ) : <EOL> self . axiom = a_ <EOL> def useLength ( self , l_ ) : <EOL> self . startLength = l_ <EOL> def useTheta ( self , t_ ) : <EOL> self . theta = radians ( t_ ) <EOL> def reset ( self ) : <EOL> self . production = self . axiom <EOL> self . drawLength = self . startLength <EOL> self . generations = <NUM_LIT:0> <EOL> def getAge ( self ) : <EOL> return self . generations <EOL> def render ( self ) : <EOL> translate ( width , height ) <EOL> repeats = <NUM_LIT:1> <EOL> self . steps += <NUM_LIT:3> <EOL> if self . steps > len ( self . production ) : <EOL> self . steps = len ( self . production ) <EOL> for i in range ( self . steps ) : <EOL> step = self . production [ i ] <EOL> if step == '<STR_LIT:F>' : <EOL> for j in range ( repeats ) : <EOL> line ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , - self . drawLength ) <EOL> translate ( <NUM_LIT:0> , - self . drawLength ) <EOL> repeats = <NUM_LIT:1> <EOL> elif step == '<STR_LIT:+>' : <EOL> for j in range ( repeats ) : <EOL> rotate ( self . theta ) <EOL> repeats = <NUM_LIT:1> <EOL> elif step == '<STR_LIT:->' : <EOL> for j in range ( repeats ) : <EOL> rotate ( - self . theta ) <EOL> repeats = <NUM_LIT:1> <EOL> elif step == '<STR_LIT:[>' : <EOL> pushMatrix ( ) <EOL> elif step == '<STR_LIT:]>' : <EOL> popMatrix ( ) <EOL> elif <NUM_LIT> <= ord ( step ) <= <NUM_LIT> : <EOL> repeats += ord ( step ) - <NUM_LIT> <EOL> def iterate ( self , prod_ , rule_ ) : <EOL> newProduction = "<STR_LIT>" <EOL> for i in range ( len ( prod_ ) ) : <EOL> step = self . production [ i ] <EOL> if step == '<STR_LIT:F>' : <EOL> newProduction = newProduction + self . ruleF <EOL> elif step != '<STR_LIT:F>' : <EOL> newProduction = newProduction + step <EOL> self . drawLength = self . drawLength * <NUM_LIT> <EOL> self . generations += <NUM_LIT:1> <EOL> return newProduction </s>
