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(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_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 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 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): 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()
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
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()
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)