Example #1
0
    def __init__(self, width, height, filename, start=Vector(0, 0)):
        global o, a

        self.t = Turtle(stroke=o.color, strokeWidth=str(o.line))
        self.width = int(math.ceil(width))
        self.height = int(math.ceil(height))
        self.filename = filename
        self.t.moveTo(start)
        self.t.setOrientation(Vector(1, 0))
        self.t.penDown()
Example #2
0
    def gen(self, svg):
        # outlines
        if self.opt.outline:
            t = Turtle(fill="lightgrey")
            t.moveTo(Vector(self.sx, self.sy))
            t.penDown()
            for i in self.edges:
                p = i.basic(t)
                t.right(90)
            t.finish()

            for i in t.getSVGElements():
                svg.addElement(i)

        ## fill
        # bodge up the insets
        self.edges[0].length = self.edges[0].length - self.edges[
            1].inset - self.edges[3].inset
        self.edges[1].length = self.edges[1].length - self.edges[
            0].inset - self.edges[2].inset
        self.edges[2].length = self.edges[2].length - self.edges[
            3].inset - self.edges[1].inset
        self.edges[3].length = self.edges[3].length - self.edges[
            2].inset - self.edges[0].inset
        #gr = g()
        gr = a()
        #		gr.set_xlink_href('./?face='+self.name)
        #		gr.set_target('_parent')
        t = Turtle()
        t.moveTo(
            Vector(self.sx + self.edges[3].inset,
                   self.sy + self.edges[0].inset))
        t.penDown()
        for i in self.edges:
            p = i.gen(t)
            t.right(90)
        t.penUp()
        t.finish()
        for i in t.getSVGElements():
            gr.addElement(i)
        if self.opt.show_labels:
            te = text(self.name, self.sx + self.width / 2,
                      self.sy + self.length / 2)
            te.setAttribute("text-anchor", "middle")
            gr.addElement(te)
        svg.addElement(gr)
Example #3
0
def testLindenMayer():
    s = Svg(0, 0, 2000, 2000)
    commands = 'F+F-F-FF+F+F-F+F+F-F-FF+F+F-F+F+F-F-FF+F+F-F+F+F-F-FF+F+F-F'
    t = Turtle()
    t.moveTo(Vector(500, 250))
    t.penDown()
    angle = 90
    distance = 40
    for cmd in commands:
        print(cmd)
        if cmd == 'F':
            t.forward(distance)
        elif cmd == '+':
            t.right(angle)
        elif cmd == '-':
            t.left(angle)
        print(t.getPosition())
    t.penDown()
    print(t.getXML())
    s = t.addTurtlePathToSVG(s)
    s.save('./testoutput/testTurtle.svg')
Example #4
0
 def v(self, x, y):
     return Vector(x, y)
Example #5
0
 def south(self):
     self.t.setOrientation(Vector(0, 1))
Example #6
0
 def west(self):
     self.t.setOrientation(Vector(-1, 0))
Example #7
0
 def north(self):
     self.t.setOrientation(Vector(0, -1))
Example #8
0
 def east(self):
     self.t.setOrientation(Vector(1, 0))
Example #9
0
 def relocate(self, x=0, y=0, v=None):
     if not v:
         v = Vector(x, y)
     self.t.penUp()
     self.t.moveTo(v)
     self.t.penDown()
Example #10
0
 def shift(self, x=0, y=0, v=None):
     if not v:
         v = Vector(x, y)
     self.t.moveTo(self.t.getPosition() + v)
Example #11
0
 def move(self, x=0, y=0, v=None):
     if not v:
         v = Vector(x, y)
     self.t.moveTo(v)