Esempio n. 1
0
    def build_path(self, text, horizontal=True, do_kerning=True):
        old_matrix = VG.get_matrix()
        VG.load_identity()

        path = VG.Path()

        #Kerning and vertical layouts are mutually exclusive in Freetype
        if do_kerning and horizontal and self.face.has_kerning:
            last_glyph = None
            for char in text:
                glyph = self.get_glyph(char)
                subpath = self.get_path_for_glyph(glyph)
                if last_glyph is not None:
                    kerning = self.face.get_kerning(last_glyph.index,
                                                    glyph.index,
                                                    FT_KERNING_UNSCALED)
                    VG.translate(self.scale*kerning[0], self.scale*kerning[1])
                last_glyph = glyph

                subpath.transform(path)
                VG.translate(self.scale*glyph.advance[0], 0.0)
        else:
            for char in text:
                glyph = self.get_glyph(char)
                subpath = self.get_path_for_glyph(glyph)
                subpath.transform(path)
                VG.translate(self.scale*glyph.advance[0]*horizontal,
                             self.scale*glyph.advance[1]*(not horizontal))

        VG.load_matrix(old_matrix)
        return path
Esempio n. 2
0
    def draw(self):
        if self.transform:
            mat = VG.get_matrix()
            VG.mult_matrix(self.transform)

        self.path.draw(self.paint_mode, style=self.style)

        if self.transform:
            VG.load_matrix(mat)
    def draw(self):
        with self.style:
            VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE)
            old_matrix = VG.get_matrix()
            
            VG.translate(*self.body.position)
            VG.rotate(math.degrees(self.body.angle))

            self.path.draw(VG_STROKE_PATH)
            VG.load_matrix(old_matrix)
Esempio n. 4
0
    def draw(self):
        mat = VG.get_matrix()
        VG.translate(*self.chassis.body.position)
        VG.rotate(math.degrees(self.chassis.body.angle))

##        self.chassis_path.draw(VG_STROKE_PATH | VG_FILL_PATH)

        VG.load_matrix(mat)
        p = VG.Path()
        points = self.chassis.get_points()
        p.move_to(points[0]+self.chassis.offset)
        for point in points[1:]:
            p.move_to(point+self.chassis.offset)
        p.close()

        p.style = VG.Style(fill_paint=VG.ColorPaint((1.0, 0.0,0.0)))
        p.draw(VG_FILL_PATH)

        VG.load_matrix(mat)
        VG.translate(*self.wheel1.body.position)
        VG.rotate(math.degrees(self.wheel1.body.angle))
        self.wheel_path.draw(VG_STROKE_PATH | VG_FILL_PATH)

        VG.load_matrix(mat)
        VG.translate(*self.wheel2.body.position)
        VG.rotate(math.degrees(self.wheel2.body.angle))
        self.wheel_path.draw(VG_STROKE_PATH | VG_FILL_PATH)

        VG.load_matrix(mat)
Esempio n. 5
0
    def draw(self):
        if self.transform:
            mat = VG.get_matrix()
            VG.mult_matrix(self.transform)

        if self.style:
            self.style.enable()

        for child in self.drawables:
            child.draw()

        if self.style:
            self.style.disable()
        
        if self.transform:
            VG.load_matrix(mat)
Esempio n. 6
0
    def draw(self):
        if self.transform:
            mat = VG.get_matrix()
            VG.mult_matrix(self.transform)

        if self.style:
            self.style.enable()

        for child in self.drawables:
            if isinstance(child, VG.Path):
                child.draw(self.paint_mode)
            else:
                child.draw()

        if self.style:
            self.style.disable()
        
        if self.transform:
            VG.load_matrix(mat)
Esempio n. 7
0
    def build_path(self, string, index, ctp):
        ctp_x, ctp_y = ctp
        
        path = VG.Path()
        vertical = False
        with VG.push([1,0,0,0,1,0,0,0,1]):
            #TODO: vertical and bidi text.
            last_glyph = None
            for char in string:
                ctp_x, ctp_y = self._transform(ctp_x, ctp_y, index)
                glyph = self.font.get_glyph(char)
                subpath = self.font.get_path_for_glyph(glyph)
                #Flip it.
                with VG.push([1,0,0,0,-1,0,0,0,1]):
                    subpath = subpath.transform()
                
                VG.translate(ctp_x, ctp_y)
                if self.font.face.has_kerning and last_glyph is not None:
                    kerning = self.font.face.get_kerning(last_glyph.index,
                                                         glyph.index,
                                                         FT_KERNING_UNSCALED)
                    VG.translate(self.font.scale*kerning[0],
                                 self.font.scale*kerning[1])
                    ctp_x += self.font.scale*kerning[0]
                    ctp_y += self.font.scale*kerning[1]
                
                if index < len(self.trot)-1:
                    VG.translate(ctp_x, ctp_y)
                    VG.rotate(self.rotate[index])
                    VG.translate(-ctp_x, -ctp_y)

                last_glyph = glyph
                
                subpath.transform(path)
                ctp_x += self.font.scale*glyph.advance[0]
                ctp_y += self.font.scale*glyph.advance[1]*vertical
                VG.load_matrix([1,0,0,0,1,0,0,0,1])

        return path, ctp
Esempio n. 8
0
    def render(self):
        if pe.vg_mode == 1:
            smack = 1 / 2048.0
            glScale(smack, smack, 1.0)

            #        VG.set(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND)

            VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE)
            VG.load_identity()
            VG.scale(1.0 / smack, 1.0 / smack)

            p = VG.Path()
            p.move_to((0, 0))
            VG.set(VG_STROKE_LINE_WIDTH, 0.01)

            #       VGU.rect(p, (0,0), (pe.q1,pe.q2))
            #       VGU.rect(p, (0,0), (x,y))
            #       VGU.arc(p, (0,0), (pe.q1,pe.q2),
            #               0, 2*pi,
            #               0xF100)
            #        VGU.arc(p, (0,0), (.5,.5), 0, 90, 0xF100)
            #        r = pe.q1
            #        p.move_to((0,r))
            #        p.arc_to((r,0), r, r, 0, False, False)

            #        paint = VG.ColorPaint((0.0, 1.0, 1.0, 1.0))
            #        VG.set_paint(paint, VG_STROKE_PATH)

            #        p.draw(VG_STROKE_PATH);

            #        self.wheel(NUM_SEGMENTS, DUTY_CYCLE, OUTER_RADIUS, INNER_RADIUS, LINE_WIDTH,
            #                   0, 1, 1)

            RADIUS = 0.2 * (sin(pe.time) + 1.0) / 2.0 * 3.0
            COUNT = 10
            SIZE = 0.2
            BIAS = pe.time / COUNT * 2 * pi
            for i in range(0, COUNT):
                saved = VG.get_matrix()
                angle = 2 * pi * (float(i) / COUNT) + BIAS
                VG.translate(RADIUS * cos(angle), RADIUS * sin(angle))
                VG.scale(SIZE, SIZE)
                VG.rotate(pe.time * 2 * pi * 10.0 + float(i) / COUNT * 2 * pi * 2.0)
                self.wheel(5, DUTY_CYCLE, OUTER_RADIUS, INNER_RADIUS, LINE_WIDTH, float(COUNT), 1, 1)
                VG.load_matrix(saved)

            return

            GRID_X = 5
            GRID_Y = 5
            idx = 0
            seed(int(pe.time))
            step = pe.time - int(pe.time)
            phase = sin(step * pi)
            for j in range(0, GRID_Y):
                for i in range(0, GRID_X):
                    saved = VG.get_matrix()
                    VG.translate((i + 0.5) / GRID_X * 2 - 1, (j + 0.5) / GRID_Y * 2 - 1)
                    VG.scale(2.0 / GRID_X, 2.0 / GRID_Y)
                    #                if random() < .1:
                    #                    VG.scale(1.0+phase,1.0+phase)
                    VG.scale(pe.bass + 1.0, pe.treb + 1.0)
                    VG.rotate(float(i) / GRID_X * 360.0 * pe.time)

                    # awesome
                    #                VG.translate(sin(pe.time+i/GRID_Y),0)

                    segments = min(j + 1, GRID_Y - j)
                    flag = True if ((j + 2) % (i + 2)) and ((i + 2) % (j + 2)) else False

                    self.wheel(
                        segments,
                        DUTY_CYCLE,
                        OUTER_RADIUS,
                        INNER_RADIUS,
                        LINE_WIDTH,
                        float(i) / GRID_X,
                        sin(float(i) / GRID_X * pi) + sin(pe.time) * 2 * pi,
                        1,
                    )
                    VG.load_matrix(saved)
Esempio n. 9
0
    def __init__(self, space, pos):
        self.input_power = 0.0

        doc = parse_svg("data/openvg.svg")

        svg_logo = doc.find(".//{http://www.w3.org/2000/svg}path")
        
        logo = svg_logo.path
        logo.style = svg_logo.style
        (x, y), (width, height) = logo.bounds()
        self.chassis_path = VG.Path()
        VGU.rect(self.chassis_path, (x-width/2.0, y-height/2.0), (width, height))
        VG.load_matrix([1,  0,      0,
                        0, -1,      0,
                        -width/2.0+x, height/2.0+y, 1])
        logo.transform(self.chassis_path)
        
        del logo
        del svg_logo
        del doc
        
        VG.load_identity()
        
        chassis_mass = 5.0
        vertices = [(width, 0), (width, height),
                    (0,  height), (0, 0)]
##        vertices = [(x, y), (x, y + height), (x + width, y + height), (x + width, y)]
        print vertices

        chassis_moment = pymunk.moment_for_poly(chassis_mass, vertices, (-x-width/2.0,-y-height/2.0))

        chassis_body = pymunk.Body(chassis_mass, chassis_moment)
        chassis_body.position = pos
        space.add(chassis_body)

        self.wheel_offset_x = width/2.0
        self.wheel_offset_y = height/2.0

        wheel_radius = 15.0
        wheel_mass = 1.0
        wheel_moment = pymunk.moment_for_circle(wheel_mass, wheel_radius, 0.0, (0,0))
        
        wheel1_body = pymunk.Body(wheel_mass, wheel_moment)
        wheel2_body = pymunk.Body(wheel_mass, wheel_moment)
        
        wheel1_body.position = (pos[0]-self.wheel_offset_x, pos[1]-self.wheel_offset_y)
        wheel2_body.position = (pos[0]+self.wheel_offset_x, pos[1]-self.wheel_offset_y)
        space.add(wheel1_body, wheel2_body)

        space.add(pymunk.PinJoint(chassis_body, wheel1_body, (0,0), (0,0)))
        space.add(pymunk.PinJoint(chassis_body, wheel2_body, (0,0), (0,0)))

        self.chassis = pymunk.Poly(chassis_body, vertices, (-x-width/2.0,-y-height/2.0))
        self.chassis.friction = 0.5
        self.chassis.offset = (-x-width/2.0,-y-height/2.0)
        space.add(self.chassis)

        self.wheel1 = pymunk.Circle(wheel1_body, wheel_radius, (0,0))
        self.wheel1.friction = 1.5
        space.add(self.wheel1)

        self.wheel2 = pymunk.Circle(wheel2_body, wheel_radius, (0,0))
        self.wheel2.friction = 1.5
        space.add(self.wheel2)

        self.wheel_path = VG.Path()
        VGU.ellipse(self.wheel_path, (0,0), (wheel_radius/2.0,wheel_radius/2.0))
        VGU.ellipse(self.wheel_path, (0,0), (wheel_radius*2.0,wheel_radius*2.0))
        VGU.ellipse(self.wheel_path, (wheel_radius-wheel_radius/4.0,0.0), (wheel_radius/8.0,wheel_radius/8.0))

        white_paint = VG.ColorPaint((1.0, 1.0, 1.0))
        grey_paint = VG.ColorPaint((0.5, 0.5, 0.5))
        black_paint = VG.ColorPaint((0.0, 0.0, 0.0))
        self.chassis_path.style = VG.Style(fill_paint=black_paint,
                                           stroke_paint=black_paint)

        self.wheel_path.style = VG.Style(fill_paint=grey_paint,
                                         stroke_paint=black_paint)