def render(self): smack = 1/2048.0 glScale(smack,smack,1.0) 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.5,-0.5)) VG.set(VG_STROKE_LINE_WIDTH, .01) pe.wave_a=0 pe.square_a=0 r = pe.mid theta = pe.time #VGU.round_rect(p, (-0.5,-0.5), (1,1), 1-pe.bass, 1-pe.bass) p.quad_to((-r*cos(theta), r*sin(theta)), (0.5, -0.5)) p.quad_to((-r*cos(theta), r*sin(theta)), (0, 0.5)) p.quad_to((-r*cos(theta), r*sin(theta)), (-0.5, -0.5)) paint = VG.ColorPaint((pe.wave_r, pe.wave_g, pe.wave_b, 1.0)) VG.set_paint(paint, VG_STROKE_PATH) paint = VG.ColorPaint((1-pe.wave_r, 1-pe.wave_g, 1-pe.wave_b, 1.0)) VG.set_paint(paint, VG_FILL_PATH) p.draw(VG_FILL_PATH) p.draw(VG_STROKE_PATH)
def render(self): return smack = 1/2048.0 glScale(smack,smack,1.0) VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE) VG.load_identity() VG.scale(1.0/smack, 1.0/smack) # Create the path (a simple circle for now...) p = VG.Path() r = 0.1 VGU.ellipse(p, (pe.kaleidoscope_x,pe.kaleidoscope_y), (r,r)) # Set up the drawing and painting parameters pe.vg_stroke_r = 0.5 + 0.35 * math.sin(7/10.0*pe.time) pe.vg_stroke_g = 0.5 + 0.35 * math.sin(11/10.0*pe.time) pe.vg_stroke_g = 0.5 + 0.35 * math.sin(13/10.0*pe.time) pe.vg_stroke_a = 1.0; pe.vg_fill_r = 1.0 - pe.vg_stroke_r pe.vg_fill_g = 1.0 - pe.vg_stroke_g pe.vg_fill_g = 1.0 - pe.vg_stroke_b VG.set(VG_STROKE_LINE_WIDTH, pe.vg_stroke_thickness) paint = VG.ColorPaint((pe.vg_stroke_r, pe.vg_stroke_g, pe.vg_stroke_b, pe.vg_stroke_a)) VG.set_paint(paint, VG_STROKE_PATH) paint = VG.ColorPaint((pe.vg_fill_r, pe.vg_fill_g, pe.vg_fill_b, pe.vg_fill_a)) VG.set_paint(paint, VG_FILL_PATH) p.draw(VG_FILL_PATH) p.draw(VG_STROKE_PATH)
def render_bg_old(self): smack = 1/2048.0 glScale(smack,smack,1.0) VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE) VG.load_identity() VG.scale(1.0/smack, 1.0/smack) here = -1 idx = 0 while here < 1: width = random()*.2*3 p = VG.Path() p.move_to((-5,here+width/2)) p.line_to((5,here+width/2 + random()*.1)) v = random() VG.set(VG_STROKE_LINE_WIDTH, width) paint = VG.ColorPaint((0.0, 0.0, 0.0, 1.0)) VG.set_paint(paint, VG_STROKE_PATH) p.draw(VG_STROKE_PATH) VG.set(VG_STROKE_LINE_WIDTH, width*.85) paint = VG.ColorPaint((v, v, v, 1.0)) VG.set_paint(paint, VG_STROKE_PATH) p.draw(VG_STROKE_PATH) here += width
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("Rainbow Gradient Test") VG.create_context((width, height)) VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0)) canvas = VG.Path(capabilities=VG_PATH_CAPABILITY_APPEND_TO) VGU.rect(canvas, (0, 0), (width, height)) rgb_gradient = VG.GradientPaint([(0,0), (width,0)], linear=True) rgb_gradient.spread_mode = VG_COLOR_RAMP_SPREAD_REFLECT rgb_gradient.stops = generate_rgb_stops(7) alpha_stops = [(0.0, (0.0, 0.0, 0.0, 0.0)), (1.0, (1.0, 1.0, 1.0, 1.0))] alpha_gradient = VG.GradientPaint([(0,0), (0,height)], linear=True) alpha_gradient.spread_mode = VG_COLOR_RAMP_SPREAD_REFLECT alpha_gradient.stops = alpha_stops n = 7 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: n += 1 rgb_gradient.stops = generate_rgb_stops(n) elif e.button == 5: if n > 2: n -= 1 rgb_gradient.stops = generate_rgb_stops(n) VG.clear((0, 0), (640, 480)) VG.set_paint(rgb_gradient, VG_FILL_PATH) canvas.draw(VG_FILL_PATH) VG.set_paint(alpha_gradient, VG_FILL_PATH) canvas.draw(VG_FILL_PATH) pygame.display.flip()
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("Polyline test") VG.create_context((width, height)) VG.set(VG_CLEAR_COLOR, (1.0, 1.0, 1.0, 1.0)) polyline = VG.Path() stroke_paint = VG.ColorPaint((0.5, 0.2, 0.8, 0.6)) VG.set_paint(stroke_paint, VG_STROKE_PATH) fill_paint = VG.ColorPaint((0.3, 1.0, 0.0, 0.6)) VG.set_paint(fill_paint, VG_FILL_PATH) polyline.style = VG.Style(VG_STROKE_LINE_WIDTH = 4.0, VG_STROKE_JOIN_STYLE = VG_JOIN_MITER, VG_STROKE_CAP_STYLE = VG_CAP_ROUND) print "Usage" print "Left click: LINE_TO" print "Right click: MOVE_TO" running = True first_click = 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: #left button if first_click: polyline.move_to((e.pos[0], height-e.pos[1]), rel=False) first_click = False else: polyline.line_to((e.pos[0], height-e.pos[1]), rel=False) elif e.button == 3:#right button polyline.move_to((e.pos[0], height-e.pos[1]), rel=False) VG.clear((0, 0), (width, height)) polyline.draw(VG_STROKE_PATH) pygame.display.flip()
def draw(self): 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)) old_paint = VG.get_paint(VG_FILL_PATH) VG.set_paint(self.fill_paint, VG_FILL_PATH) with self.style: self.path.draw(VG_STROKE_PATH | VG_FILL_PATH) VG.set_paint(old_paint, VG_FILL_PATH) VG.load_matrix(old_matrix)
def render(self): if (pe.square_a != 0.0 and pe.vg_mode == 3): VG.set(VG_STROKE_LINE_WIDTH, 15.0) fill_paint = VG.ColorPaint((pe.square_r, pe.square_g, pe.square_b, pe.square_a)) stroke_paint = VG.ColorPaint(( 0.65 + 0.350*( 0.60*math.sin(0.742*pe.time) + 0.40*math.sin(1.021*pe.time) ), 0.65 + 0.350*( 0.60*math.sin(0.703*pe.time) + 0.40*math.sin(0.969*pe.time) ), 0.65 + 0.350*( 0.60*math.sin(1.090*pe.time) + 0.40*math.sin(0.963*pe.time) ), pe.square_a)) VG.set_paint(fill_paint, VG_FILL_PATH) VG.set_paint(stroke_paint, VG_STROKE_PATH) p = VG.Path(capabilities=VG_PATH_CAPABILITY_APPEND_TO) vx=self.vr*math.cos(self.vt) vy=self.vr*math.sin(self.vt) p.move_to((self.x,self.y)) self.x+=vx self.y+=vy p.line_to((self.x,self.y)) VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE) VG.load_identity() VG.scale(0.001, 0.001) p.draw(VG_STROKE_PATH); if random()<.01: self.at = 0 if self.x<-1000 or self.x>1000 or self.y<-1000 or self.y>1000: self.x=0 self.y=0 self.vt += (random()-.5)*.1 self.vt += self.at self.at += (random()-.5)*.1
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()
def wheel(self, num_segments, duty_cycle, outer_radius, inner_radius, line_width, color_bias, saturation, value): VG.set(VG_STROKE_LINE_WIDTH, 0.05) for i in range(0, num_segments): inner = 2 * pi / num_segments * (i + 0.5) inner_x = inner_radius * cos(inner) inner_y = inner_radius * sin(inner) p = VG.Path() r_start = 360.0 / num_segments * i r_dist = 360.0 / num_segments * duty_cycle p.move_to((inner_x, inner_y)) VGU.arc(p, (0, 0), (outer_radius * 2, outer_radius * 2), r_start, r_dist, 0xF100) p.line_to((inner_x, inner_y)) # XXX doesn't join to arc start quite correctly p.line_to((outer_radius * cos(r_start / 360.0 * 2 * pi), outer_radius * sin(r_start / 360.0 * 2 * pi))) (r, g, b) = hsv_to_rgb(float(i) / num_segments + color_bias * 2 * pi, saturation, value) paint = VG.ColorPaint((0, 0, 0, 1.0)) VG.set_paint(paint, VG_STROKE_PATH) paint = VG.ColorPaint((r, g, b, 1.0)) VG.set_paint(paint, VG_FILL_PATH) p.draw(VG_FILL_PATH) p.draw(VG_STROKE_PATH)
def render_bg(self): return self.update() smack = 1/2048.0 glScale(smack,smack,1.0) VG.set(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE) VG.load_identity() VG.scale(1.0/smack, 1.0/smack) idx = 0 while 1: here = self.offsets[idx] width = self.offsets[idx+1]-here disp = self.displacements[idx] v = self.values[idx] idx += 1 if here > 1.0: break p = VG.Path() p.move_to((-5,here+width/2)) p.line_to((5,here+width/2 + disp)) VG.set(VG_STROKE_LINE_WIDTH, width) paint = VG.ColorPaint((0.0, 0.0, 0.0, 1.0)) VG.set_paint(paint, VG_STROKE_PATH) p.draw(VG_STROKE_PATH) VG.set(VG_STROKE_LINE_WIDTH, width*.85) paint = VG.ColorPaint((v, v, v, 1.0)) VG.set_paint(paint, VG_STROKE_PATH) p.draw(VG_STROKE_PATH)
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()