lsystem.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:L-Systems-Compiler-And-Renderer 作者: Mizzlr 项目源码 文件源码
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"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号