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):
        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. 3
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. 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 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)