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. 2
0
def center_and_concat(p1, p2):
    (dx, dy), (dw, dh) = p1.bounds()
    (sx, sy), (sw, sh) = p2.bounds()

    dst_cx, dst_cy = (dx+dw/2.0), (dy+dh/2.0)
    src_cx, src_cy = (sx+sw/2.0), (sy+sh/2.0)

    VG.translate(dst_cx-src_cx, dst_cy-src_cy)
    p2.transform(p1)
    VG.load_identity()
Esempio n. 3
0
def main(width, height, path, flags=0):
    pygame.init()
    
    pygame.display.gl_set_attribute(pygame.GL_STENCIL_SIZE, 2)

    flags |= pygame.OPENGL | pygame.DOUBLEBUF
    
    screen = pygame.display.set_mode((width, height), flags)
    pygame.display.set_caption("Pygame Image Draw Test")
    
    VG.create_context((width, height))
    VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0))

    im = load_image(path)
    dump_image(im)

    dest_x = (width-im.width)/2.0
    dest_y = (height-im.height)/2.0
    dragging = False
    
    running = True
    while running:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                running = False
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    running = False
            elif e.type == pygame.MOUSEBUTTONDOWN:
                if e.button == 1:
                    dragging = True
            elif e.type == pygame.MOUSEBUTTONUP:
                if e.button == 1:
                    dragging = False
            elif e.type == pygame.MOUSEMOTION:
                if dragging:
                    dest_x += e.rel[0]
                    dest_y -= e.rel[1]

        VG.clear((0, 0), (width, height))
        
        VG.set(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE)
        VG.load_identity()
        
        VG.translate(dest_x, dest_y)

        im.draw()
        
        pygame.display.flip()
def main(width, height, message, rpm=20):
    pygame.init()
    
    pygame.display.gl_set_attribute(pygame.GL_STENCIL_SIZE, 2)
    srf = pygame.display.set_mode((width, height), pygame.OPENGL | pygame.DOUBLEBUF)
    pygame.display.set_caption("Freetype Font test")
    
    VG.create_context((width, height))
    VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0))

    font = Font("data/fonts/Vera.ttf", 64)

    red_paint = VG.ColorPaint((1.0, 0.0, 0.0, 1.0))
    text = font.build_path(message)
    (x, y), (w, h) = text.bounds()

    text.style = VG.Style(VG_STROKE_LINE_WIDTH = 1.0,
                          fill_paint = red_paint)

    clock = pygame.time.Clock()
    dt = 0

    cx = width/2.0 - w/2.0
    cy = height/2.0 - h/2.0
    
    running = True
    while running:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                running = False
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    running = False
            elif e.type == pygame.MOUSEBUTTONDOWN:
                pos = e.pos
                cx = pos[0]  - w/2.0
                cy = height-pos[1]  - h/2.0

        VG.clear((0, 0), (width, height))
        VG.load_identity()

        VG.translate(cx, cy)
        rotate_about((x+w/2.0, y+h/2.0), dt*360.0*rpm / (60*1000.0))

        text.draw(VG_STROKE_PATH | VG_FILL_PATH)
        
        pygame.display.flip()
        dt += clock.tick(60)
Esempio n. 5
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. 6
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. 7
0
def main():
    pygame.init()
    
    pygame.display.gl_set_attribute(pygame.GL_STENCIL_SIZE, 2)
    srf = pygame.display.set_mode((640,480), pygame.OPENGL | pygame.DOUBLEBUF)
    pygame.display.set_caption("Paint test")
    
    
    VG.create_context((640, 480))
    VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0))
    VG.set(VG_STROKE_LINE_WIDTH, 3.0)

    p = VG.Path(capabilities=VG_PATH_CAPABILITY_APPEND_TO)
    VGU.ellipse(p, (0, 0), (64*2,64*2))

    solid_paint = VG.ColorPaint((1.0, 0.0, 1.0))

    stops = [(0.0,(1.0,1.0,1.0,1.0)), (0.333,(1.0,0.0,0.0,1.0)), (0.666,(0.0,1.0,0.0,1.0)), (1.0,(0.0,0.0,1.0,1.0))]

    linear_gradient = [(-60,0), (60,0)]
    linear_paint = VG.GradientPaint(linear_gradient, linear=True)
    linear_paint.spread_mode = VG_COLOR_RAMP_SPREAD_REFLECT
    linear_paint.stops = stops

    radial_gradient = [(0,0), (0,0), 64]
    radial_paint = VG.GradientPaint(radial_gradient, linear=False)
    radial_paint.stops = stops


    running = True
    while running:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                running = False
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    running = False

        VG.clear((0, 0), (640, 480))
        
        VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE)
        VG.load_identity()

        VG.translate(68, 240-64)
        VG.set_paint(solid_paint, VG_FILL_PATH)
        p.draw(VG_STROKE_PATH | VG_FILL_PATH)

        VG.translate(192, 0)
        VG.set_paint(linear_paint, VG_FILL_PATH)
        p.draw(VG_STROKE_PATH | VG_FILL_PATH)

        VG.translate(192, 0)
        VG.set_paint(radial_paint, VG_FILL_PATH)
        p.draw(VG_STROKE_PATH | VG_FILL_PATH)
        
        pygame.display.flip()
Esempio n. 8
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
def rotate_about(p, angle):
    VG.translate(p[0], p[1])
    VG.rotate(angle)
    VG.translate(-p[0], -p[1])
Esempio n. 10
0
def main(width, height):
    pygame.init()

    pygame.display.gl_set_attribute(pygame.GL_STENCIL_SIZE, 2)
    pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLEBUFFERS, 1)
    pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLESAMPLES, 4)
    screen = pygame.display.set_mode((width, height), pygame.OPENGL | pygame.DOUBLEBUF)
    pygame.display.set_caption("Flower test")
    
    
    VG.create_context((width, height))
    VG.set(VG_CLEAR_COLOR, (0.0, 0.0, 0.0, 1.0))

    vera = Font("data/fonts/Vera.ttf", 32)

    message = vera.build_path("Hold down LMB to create flowers")
    message.style = VG.Style(fill_paint=VG.ColorPaint((1.0, 1.0, 1.0, 0.7)))

    doc = parse_svg("data/svg/flower.svg")
    
    flower = doc.getroot()
    (x,y), (w,h) = flower.bounds()
    cx,cy = x+w/2.0, y+h/2.0
    
    particles = []
    to_remove = []

    clock = pygame.time.Clock()
    dt = 0
    running = True
    while running:
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                running = False
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    running = False

        if pygame.mouse.get_pressed()[0]:
            x,y = pygame.mouse.get_pos()
            m = random.randint(-60, 60)
            angle = random.randint(0,359)

            pos = (x-cx, height-y-cy)
            vel = (m*math.cos(math.radians(angle)),
                   m*math.sin(math.radians(angle)))
            rot = random.randint(-30, 30)
            scale = random.randint(8, 12)/10.0
            particles.append([pos, vel, random.randint(0,359), rot, scale])

        VG.clear((0,0), (width, height))
        
        for particle in particles:
            VG.load_identity()
            pos, vel, angle, rot, scale = particle
            VG.translate(pos[0]+cx, pos[1]+cy)
            VG.scale(scale, scale)
            VG.rotate(angle)
            VG.translate(-cx, -cy)
            flower.draw()

            particle[0] = (pos[0]+vel[0]*dt/1000.0,pos[1]+vel[1]*dt/1000.0)
            particle[2] += rot * dt/1000.0
            
            if particle[0][0] + w < 0 or particle[0][1] + h < 0:
                to_remove.append(particle)
            elif particle[0][0] - w > width or particle[0][1] - h > height:
                to_remove.append(particle)

        particles = [particle for particle in particles if particle not in to_remove]
        del to_remove[:]

        VG.load_identity()
        message.draw(VG_FILL_PATH)

        dt = clock.tick(30)
        pygame.display.flip()
Esempio n. 11
0
def main(width, height):
    pygame.init()
    
    pygame.display.gl_set_attribute(pygame.GL_STENCIL_SIZE, 2)
    srf = pygame.display.set_mode((width, height), pygame.OPENGL | pygame.DOUBLEBUF)
    pygame.display.set_caption("Interpolation test")
    
    
    VG.create_context((width, height))
    VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0))

    paths = []
    path_tag = ".//{http://www.w3.org/2000/svg}path"

    VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE)
    VG.scale(5.0, 5.0)

    doc = parse_svg("data/svg/shapes.svg")
    
    for element in doc.findall(path_tag):
        path = element.path.transform()
        path.style = element.style
        if not path.style:
            path.style = VG.Style(VG_STROKE_LINE_WIDTH=5.0)
        else:
            path.style[VG_STROKE_LINE_WIDTH] *= 2
        paths.append(path)

    VG.load_identity()

    morph = VG.Path()
    start = paths[0]
    end = paths[1]
    morph.style = start.style

    VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE)
    VG.translate(220, 140)

    clock = pygame.time.Clock()

    running = True
    dt = 0
    i = 0
    while running:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                running = False
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    running = False

        VG.clear((0, 0), (width, height))

        morph.clear()
        VG.interpolate(start, end, morph, dt/float(MORPH_TIME))

        morph.draw(VG_STROKE_PATH)
        
        pygame.display.flip()

        dt += clock.tick(60)
        if dt >= MORPH_TIME:
            dt -= MORPH_TIME
            i += 1
            start = paths[i % len(paths)]
            end = paths[(i+1) % len(paths)]
            morph.style = start.style
Esempio n. 12
0
def main(width, height, radius, count, flags=0):
    pygame.init()
    
    pygame.display.gl_set_attribute(pygame.GL_STENCIL_SIZE, 2)

    flags |= pygame.OPENGL | pygame.DOUBLEBUF
    
    srf = pygame.display.set_mode((width, height), flags)
    pygame.display.set_caption("Blending test")
    
    
    VG.create_context((width, height))
    VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0))

    orange_paint = VG.ColorPaint((1.0, 0.5, 0.0, 0.5))
    blue_paint = VG.ColorPaint((0.0, 0.0, 1.0, 0.5))
    black_paint = VG.ColorPaint((0.0, 0.0, 0.0))

    blend_modes = [VG_BLEND_SRC, VG_BLEND_SRC_OVER, VG_BLEND_DST_OVER,
                   VG_BLEND_SRC_IN, VG_BLEND_DST_IN, VG_BLEND_MULTIPLY,
                   VG_BLEND_SCREEN, VG_BLEND_DARKEN, VG_BLEND_LIGHTEN,
                   VG_BLEND_ADDITIVE]

    blend_index = 0
    
    VG.set(VG_BLEND_MODE, blend_modes[0])

    font = Font("data/fonts/Vera.ttf", 30)
    src_path = font.build_path("SRC")
    dst_path = font.build_path("DST")
    message = font.build_path("Scroll to change the blend mode")
    
    circle = VG.Path()
    VGU.ellipse(circle, (0, 0), (radius*2, radius*2))
    center_and_concat(circle, dst_path)

    square = VG.Path()
    VGU.rect(square, (-radius, -radius), (radius*2, radius*2))
    center_and_concat(square, src_path)

    circle2 = VG.Path()
    VGU.ellipse(circle2, (0, 0), (radius*2, radius*2))

    running = True
    while running:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                running = False
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    running = False
            elif e.type == pygame.MOUSEBUTTONDOWN:
                if e.button == 4:
                    blend_index += 1
                    VG.set(VG_BLEND_MODE, blend_modes[blend_index % len(blend_modes)])
                elif e.button == 5:
                    blend_index -= 1
                    VG.set(VG_BLEND_MODE, blend_modes[blend_index % len(blend_modes)])

        VG.clear((0, 0), (width, height))
        
        VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE)
        VG.load_identity()
        VG.translate(width - radius*1.5, radius * 2.5)
        circle.draw(VG_FILL_PATH | VG_STROKE_PATH)
        VG.translate(-radius, -radius)
        VG.set_paint(orange_paint, VG_FILL_PATH)
        square.draw(VG_FILL_PATH | VG_STROKE_PATH)

        VG.set_paint(blue_paint, VG_FILL_PATH)
        for i in xrange(count):
            angle = i*2*math.pi/count
            VG.load_identity()
            VG.translate(width//2, height//2)
            VG.translate(radius*math.cos(angle), radius*math.sin(angle))
            circle2.draw(VG_FILL_PATH)

        VG.load_identity()
        (x,y), (w,h) = message.bounds()
        VG.translate(-x, height-y-h)
        message.draw(VG_STROKE_PATH | VG_FILL_PATH)
        

        
        pygame.display.flip()
Esempio n. 13
0
def main(width, height, directory):
    pygame.init()
    
    pygame.display.gl_set_attribute(pygame.GL_STENCIL_SIZE, 2)
    pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLEBUFFERS, 1)
    pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLESAMPLES, 4)
    screen = pygame.display.set_mode((width, height), pygame.OPENGL | pygame.DOUBLEBUF)
    pygame.display.set_caption("SVG Viewer")
    
    
    VG.create_context((width, height))
    VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0))

    register_font_finder(pygame.font.match_font)
    @register_font_finder
    def fallback_font(name):
        fname = pygame.font.get_default_font()
        return os.path.join(os.path.dirname(pygame.font.__file__), fname)

    vera = Font("data/fonts/Vera.ttf", 16)
    text = vera.build_path("Scroll to change svg files. Drag to see more.")

    drawings = []

    for root, dirs, files in os.walk(directory):
        for fname in files:
            if not fname.endswith(".svg"):
                continue
            path = os.path.join(root, fname)
            try:
                tree = parse_svg(path)
                name = vera.build_path(fname, 16)
                tree.getroot().fit(width, height)
                drawings.append((tree.getroot(), name))
            except:
                print "Error in loading %s" % path
                traceback.print_exc(0)
    
    dragging = False
    dx = dy = 0
    i = 0
    scale = 1
    
    drawing, name = drawings[0]
    (x,y), (w,h) = drawing.bounds()

    running = True
    while running:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                running = False
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    running = False
                elif e.key == pygame.K_1:
                    scale = 1
                elif e.key == pygame.K_2:
                    scale = 2
                elif e.key == pygame.K_3:
                    scale = 3
                elif e.key == pygame.K_4:
                    scale = 4
                elif e.key == pygame.K_5:
                    scale = 5
                elif e.key == pygame.K_6:
                    scale = 6
                elif e.key == pygame.K_7:
                    scale = 7
                elif e.key == pygame.K_8:
                    scale = 8
                elif e.key == pygame.K_9:
                    scale = 9

                elif e.key == pygame.K_EQUALS:
                    i += 1
                    drawing, name = drawings[i % len(drawings)]
                    (x,y), (w,h) = drawing.bounds()
                elif e.key == pygame.K_MINUS:
                    i -= 1
                    drawing, name = drawings[i % len(drawings)]
                    (x,y), (w,h) = drawing.bounds()
            elif e.type == pygame.MOUSEBUTTONDOWN:
                if e.button == 1 or e.button == 2 or e.button == 3:
                    dragging = True
                else:
                    if e.button == 4:
                        i += 1
                    else:
                        i -= 1
                    drawing, name = drawings[i % len(drawings)]
                    (x,y), (w,h) = drawing.bounds()
                    
            elif e.type == pygame.MOUSEBUTTONUP:
                if e.button == 1 or e.button == 2 or e.button == 3:
                    dragging = False
            elif e.type == pygame.MOUSEMOTION:
                if dragging:
                    dx += e.rel[0]/2.0**(scale-1)
                    dy -= e.rel[1]/2.0**(scale-1)

        VG.clear((0, 0), (width, height))

        
        VG.load_identity()

        VG.scale(2**(scale-1),2**(scale-1))
        VG.translate(width/2.0-w/2.0-x+dx, height/2.0-h/2.0-y+dy)

        drawing.draw()

        VG.load_identity()
        VG.translate(10, 10)
        text.draw(VG_FILL_PATH)
        VG.translate(text.bounds()[1][0]+10, 0)
        name.draw(VG_FILL_PATH)

        pygame.display.flip()
Esempio n. 14
0
def main(width, height, font_path, size):
    pygame.init()
    
    pygame.display.gl_set_attribute(pygame.GL_STENCIL_SIZE, 2)
    srf = pygame.display.set_mode((width, height), pygame.OPENGL | pygame.DOUBLEBUF)
    pygame.display.set_caption("Freetype Font test")
    
    VG.create_context((width, height))
    VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0))

    font = Font(font_path, size)
    xmin, ymin, xmax, ymax = [x*font.scale for x in font.face.bbox]

    the_path = VG.Path()

    message = font.build_path("left click and drag to move")
    (x, y), (w, h) = message.bounds()
    VG.translate(width/2.0-w/2.0, height-h)
    message.transform(the_path)

    VG.load_identity()
    VG.translate(0-xmin, height-ymax-h)
    boxes_per_line = int(width/float(xmax-xmin))
    i = 0
    for char_code, glyph in sorted(font.glyph_table.items()):
        font.get_path_for_glyph(glyph).transform(the_path)
        VG.translate(xmax-xmin, 0)
        i += 1
        if i >= boxes_per_line:
            VG.translate((xmax-xmin)*-boxes_per_line, ymin-ymax)
            i = 0
    VG.load_identity()

        
    red_paint = VG.ColorPaint((1.0, 0.0, 0.0, 1.0))
    style = VG.Style(VG_STROKE_LINE_WIDTH = 1.0,
                     fill_paint = red_paint)
    style.enable()

    dragging = False
    
    running = True
    while running:
        events = pygame.event.get()
        for e in events:
            if e.type == pygame.QUIT:
                running = False
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_ESCAPE:
                    running = False
            elif e.type == pygame.MOUSEBUTTONDOWN:
                if e.button == 1:
                    dragging = True
            elif e.type == pygame.MOUSEBUTTONUP:
                if e.button == 1:
                    dragging = False
            elif e.type == pygame.MOUSEMOTION:
                if dragging:
                    VG.translate(e.rel[0], -e.rel[1])

        VG.clear((0, 0), (width, height))
        
        the_path.draw(VG_STROKE_PATH | VG_FILL_PATH)

        
        pygame.display.flip()
Esempio n. 15
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. 16
0
    VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0))

    world = MoonWorld()
    low_point = min(world.terrain_data)

    running = True
    clock = pygame.time.Clock()

    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    running = False

        left_down, middle_down, right_down = pygame.mouse.get_pressed()
        world.buggy.input_power = 1.0 * (left_down - right_down)

        world.update()

        VG.clear((0,0), (640,480))
        VG.load_identity()
        pos = world.buggy.chassis.body.position
        VG.translate(-pos[0] + 300, min(-pos[1] + 200, -low_point))

        world.draw()
        
        pygame.display.flip()
        clock.tick(60)