示例#1
0
def make_glyph(glyphs):
    tempPath = None
    for paths in glyphs:
        path = Path()
        for segment in paths:
            if len(segment) == 4:
                start_x = segment[0][0]
                start_y = segment[0][1]
                cp1_x = segment[1][0]
                cp1_y = segment[1][1]
                cp2_x = segment[2][0]
                cp2_y = segment[2][1]
                end_x = segment[3][0]
                end_y = segment[3][1]
                if path.bounds.height == 0 and path.bounds.width == 0:
                    path.move_to(start_x, start_y)
                    path.add_curve(end_x, end_y, cp1_x, cp1_y, cp2_x, cp2_y)
                else:
                    path.add_curve(end_x, end_y, cp1_x, cp1_y, cp2_x, cp2_y)
            elif len(segment) == 2:
                start_x = segment[0][0]
                start_y = segment[0][1]
                end_x = segment[1][0]
                end_y = segment[1][1]
                if path.bounds.height == 0 and path.bounds.width == 0:
                    path.move_to(start_x, start_y)
                    path.line_to(end_x, end_y)
                else:
                    path.line_to(end_x, end_y)
        if tempPath:
            tempPath.append_path(path)
        else:
            tempPath = path
    return tempPath
示例#2
0
    def setup(self):
        h = 200
        w = 300
        p = Path()
        p.line_to(w / 2, h)
        p.line_to(-(w / 2), h)
        p.close()
        self.s = ShapeNode(p)
        self.s.anchor_point = (0.5, 0)
        self.s.position = (self.size.x / 2, self.size.y / 2)
        self.add_child(self.s)

        ph = Path()
        ph.line_to(self.size.x, 0)
        ph.line_to(self.size.x, 1)
        ph.line_to(0, 1)
        ph.close()
        self.lh = ShapeNode(ph)
        self.lh.fill_color = 'red'
        self.lh.position = (self.size.x / 2, self.size.y / 2)
        self.add_child(self.lh)

        pv = Path()
        pv.line_to(0, self.size.y)
        pv.line_to(1, self.size.y)
        pv.line_to(1, 0)
        pv.close()
        self.lv = ShapeNode(pv)
        self.lv.fill_color = 'red'
        self.lv.position = (self.size.x / 2, self.size.y / 2)
        self.add_child(self.lv)