def draw(self):
"draws the lsystem on the screen"
stack = []
tt.penup()
tt.setpos(0, -200)
tt.seth(90)
tt.pendown()
print "Drawing the lsystem ..."
for i, codebit in enumerate(self.generation[-1]):
if codebit in ['F', 'A', 'B']:
tt.forward(self.length)
print '[ FRWD ] ', codebit
elif codebit == '+':
tt.right(self.angle)
print '[ RGHT ] ', codebit
elif codebit == '-':
tt.left(self.angle)
print '[ LEFT ] ', codebit
elif codebit == '[':
stack.append((tt.pos(), tt.heading()))
print '[ PUSH ] ', (tt.pos(), tt.heading())
elif codebit == ']':
position,heading = stack.pop()
print '[ POP ] ', (position, heading)
tt.penup()
tt.goto(position)
tt.seth(heading)
tt.pendown()
else:
print '[ NOP ] ', codebit
if self.save_every_frame:
self.save(frame=i)
print "Done drawing"
print "Saving file as %s.jpg" % self.name,
self.save()
print "Done"
评论列表
文章目录