Exemple #1
0
 def _gen_grid(self, dx, dy, width=0.5):
     xmax, ymax = 1000, 1000
     x, y = 0, 0
     lines = []
     txt = []
     while x < xmax:
         lines.append(_transform.LineElement([(x, 0), (x, ymax)],
                                             width=width))
         txt.append(_transform.TextElement(x, dy/2, str(x), size=self.size))
         x += dx
     while y < ymax:
         lines.append(_transform.LineElement([(0, y), (xmax, y)],
                                             width=width))
         txt.append(_transform.TextElement(0, y, str(y), size=self.size))
         y += dy
     return lines+txt
Exemple #2
0
def gcode_to_svg(infile, outfile, width=760, height=580):
    w = f"{width}"
    h = f"{height}"
    drawing = False
    x1 = None
    y1 = None

    fig = sg.SVGFigure(width=w, height=h)
    fig.root.set('height', h)
    fig.root.set('width', w)

    points = [[0, 0], [width, 0], [width, height], [0, height], [0, 0]]
    rect = sg.LineElement(points, 1, "red")
    rect.root.attrib['fill'] = 'none'
    fig.append(rect)

    with open(infile) as fp:
        for cnt, line in enumerate(fp):
            if pen_down.match(line):
                drawing = True
            elif pen_up.match(line):
                drawing = False
            elif move.match(line):
                m = move.match(line)
                x = float(m.group(1))
                y = float(m.group(2))
                if drawing:
                    fig.append(sg.LineElement([[x1, y1], [x, y]], 1, "black"))
                else:
                    pass
                    #print(f"Moving from {x1},{y1} to {x},{y}")
                x1 = x
                y1 = y
            else:
                print(f"Unknown line: {line}")

    fig.save(outfile)
Exemple #3
0
    def _draw_border(self):
        # Vertical lines
        WIDTH = self._outer_board_width_pixel()
        HEIGHT = self._outer_board_height_pixel()
        X_LEFT_CENTER = self._border_thickness_pixel / 2.0
        X_RIGHT_CENTER = WIDTH - self._border_thickness_pixel / 2.0
        Y_TOP_CENTER = self._border_thickness_pixel / 2.0
        Y_BOTTOM_CENTER = HEIGHT - self._border_thickness_pixel / 2.0
        for start, end in (
                # Vertical lines
            ((X_LEFT_CENTER, 0), (X_LEFT_CENTER, HEIGHT)),
            ((X_RIGHT_CENTER, 0), (X_RIGHT_CENTER, HEIGHT)),

                # Horizontal lines
            ((0, Y_TOP_CENTER), (WIDTH, Y_TOP_CENTER)),
            ((0, Y_BOTTOM_CENTER), (WIDTH, Y_BOTTOM_CENTER)),
        ):
            line = sg.LineElement([start, end],
                                  width=self._border_thickness_pixel)
            self._lines.append(line)
Exemple #4
0
 def __init__(self, points, width=1, color='black'):
     element = _transform.LineElement(points, width=width, color=color)
     Element.__init__(self, element.root)
Exemple #5
0
 def _raw_line(self, start, end, width):
     line = sg.LineElement([start, end], width=width)
     self._lines.append(line)
def rect(x, y, w, h, width=1, color="black", fill="none"):
    points = [[x, y], [x + w, y], [x + w, y + h], [x, y + h], [x, y]]
    rect = sg.LineElement(points, width, color)
    rect.root.attrib['fill'] = fill
    return rect