def __init__(self, **kwargs): super(LinearGauge, self).__init__(**kwargs) # these values match the actual dimensions of the referenced graphic assets self.gauge_width = 2000 self.gauge_height = 500 x = self.pos[0] y = self.pos[1] scale_x = self.width / self.gauge_width scale_y = self.height / self.gauge_height with self.canvas: PushMatrix() self.dial_color = Color(rgba=self.color) self.gauge_translate = Translate(x, y, 0) self.gauge_scale = Scale(x=scale_x, y=scale_y) Rectangle(source='resource/gauge/horizontal_bar_gauge.png', pos=self.pos, size=(self.gauge_width, self.gauge_height)) PopMatrix() PushMatrix() self.mask_translate = Translate(x, y, 0) self.mask_scale = Scale(x=scale_x, y=scale_y) Rectangle(source='resource/gauge/horizontal_bar_gauge_mask.png', pos=self.pos, size=(self.gauge_width, self.gauge_height)) PopMatrix() with self.canvas.after: PushMatrix() Color(1, 1, 1, 1) self.shadow_translate = Translate(x, y, 0) self.shadow_scale = Scale(x=scale_x, y=scale_y) Rectangle(source='resource/gauge/horizontal_bar_gauge_shadow.png', pos=self.pos, size=(self.gauge_width, self.gauge_height)) PopMatrix() self.bind(pos=self.update_all, size=self.update_all)
def add_graphics(self, canvas, black_back=False): '''Adds all the graphics required to visualize the shapes to the canvas. ''' _get_app().stage_factory.remove_shapes_gl_color_instructions( canvas, self.canvas_name) self.shape_views = [] w, h = self.screen_width, self.screen_height with canvas: PushMatrix() s = Scale() if self.flip_projector: s.x = -1 s.origin = w / 2., h / 2. if black_back: with canvas: Color(0, 0, 0, 1, group=self.canvas_name) Rectangle(size=(w, h), group=self.canvas_name) if self.do_quad_mode: half_w = w // 2 half_h = h // 2 for (x, y) in ((0, 1), (1, 1), (0, 0), (1, 0)): with canvas: PushMatrix(group=self.canvas_name) Translate(x * half_w, y * half_h, group=self.canvas_name) s = Scale(group=self.canvas_name) s.x = s.y = 0.5 s.origin = 0, 0 instructs = _get_app().\ stage_factory.get_shapes_gl_color_instructions( canvas, self.canvas_name) with canvas: PopMatrix(group=self.canvas_name) self.shape_views.append(instructs) else: self.shape_views = [ _get_app().stage_factory.get_shapes_gl_color_instructions( canvas, self.canvas_name) ] with canvas: PopMatrix() if self.output_count and not self.serializer_tex: with canvas: Color(1, 1, 1, 1, group=self.canvas_name) tex = self.serializer_tex = Texture.create(size=(1, 1)) tex.mag_filter = 'nearest' tex.min_filter = 'nearest' Rectangle(texture=tex, pos=(0, h - 1), size=(1, 1), group=self.canvas_name)
def reinit_before(self, base_angle=None): """Initialize the “before” canvas, i.e., whatever's below the MazeBoard """ cell_size = self.board.cell_size if base_angle is None: base_angle = 180 if self.current_solver else 0 self.canvas.before.clear() with self.canvas.before: for player, rotation in enumerate((90, 270)): # Win/lose messages at end of game if self.round_number < NUM_ROUNDS: text = '' elif player ^ (self.times[0] < self.times[1]): text = 'Winner!' else: text = 'Second place' PushMatrix() Translate( self.board.window_width / 2, self.board.window_height / 2, 0, ) Rotate(rotation, 0, 0, 1) l = Label( text=text, pos=( -self.board.window_height / 2, -self.board.window_width / 2 + cell_size, ), size=(self.board.window_height, cell_size * 4), bold=True, font_size=cell_size * 2, color=(1, 1, 0), ) PopMatrix() PushMatrix() Translate( self.board.window_width / 2, self.board.window_height / 2, 0, ) # Instructions for animating the board self.scale_instruction = Scale(1) self.rotate_instruction = Rotate(base_angle, 0, 0, 1) Translate( -self.board.window_width / 2, -self.board.window_height / 2, 0, )
def __init__(self, norm, pos, tempo, clock, tempo_map, touch_points, block_handler): super(TempoCursor, self).__init__() self.norm = norm self.pos = pos self.size = self.norm.nt((70, 70)) self.cursor = CEllipse(cpos=pos, csize=self.size) self.add(Color(1, 1, 1)) self.add(self.cursor) self.tempo = tempo self.clock = clock self.tempo_map = tempo_map self.sched = Scheduler(self.clock, self.tempo_map) self.block_handler = block_handler # 0..15, for 16th note granularity self.touch_points = touch_points self.index = 0 # add touch markers self.add(PushMatrix()) self.add(Translate(*pos)) for touch_point in self.touch_points: self.add(Rotate(angle=-360 * touch_point / 16)) self.add(Color(159 / 255, 187 / 255, 208 / 255)) # blue self.add(Line(points=(0, 0, 0, self.norm.nv(25)), width=2)) self.add(Rotate(angle=360 * touch_point / 16)) self.add(PopMatrix()) # add current time marker self.add(PushMatrix()) self.add(Translate(*pos)) self.time_marker = Line(points=(0, 0, 0, self.norm.nv(30)), width=3) self.rotate = Rotate(angle=0) self.add(self.rotate) self.add(Color(0, 0, 0)) self.add(self.time_marker) self.add(PopMatrix()) self.on_update(0) cur_tick = self.sched.get_tick() next_tick = quantize_tick_up(cur_tick, kTicksPerQuarter * 4) next_tick += self.calculate_tick_interval(0, self.touch_points[0]) self.sched.post_at_tick(self.touch_down, next_tick)
def draw_setpoint(self, *args): # draw a setpoint if self.setpoint_canvas: self.canvas.after.remove(self.setpoint_canvas) self.setpoint_canvas = None if math.isnan(self.setpoint_value): return v = self.value_to_angle(self.setpoint_value) length = self.dial_diameter / 2.0 - self.tic_length if not self.setpoint_length else self.setpoint_length self.setpoint_canvas = InstructionGroup() self.setpoint_canvas.add(PushMatrix()) self.setpoint_canvas.add(Color(*self.setpoint_color)) self.setpoint_canvas.add( Rotate(angle=v, axis=(0, 0, -1), origin=self.dial_center)) self.setpoint_canvas.add( Translate(self.dial_center[0], self.dial_center[1])) self.setpoint_canvas.add( Line(points=[0, 0, 0, length], width=self.setpoint_thickness, cap='none')) #self.setpoint_canvas.add(SmoothLine(points=[0, 0, 0, length], width=self.setpoint_thickness)) self.setpoint_canvas.add(PopMatrix()) self.canvas.after.add(self.setpoint_canvas)
def draw_annulars(self): # draw annulars that are in the annulars list: # requires properties annular_thickness, and a list of dicts {color: , start: , stop: }, ..., # where start and stop are the values of the scale to start and stop the annular if len(self.annulars) == 0: return awidth = self.annular_thickness self.annular_canvas = InstructionGroup() if self.semi_circle: self.annular_canvas.add(PushMatrix()) self.annular_canvas.add( Translate(0, -self.dial_diameter / 2 + self.hub_radius)) for a in self.annulars: self.annular_canvas.add(Color(*a.get('color', [0, 1, 0, 1]))) st = self.value_to_angle(a.get('start', self.scale_min)) en = self.value_to_angle(a.get('stop', self.scale_max)) self.annular_canvas.add( Line(ellipse=(self.pos[0] + awidth, self.pos[1] + awidth, self.dial_diameter - awidth * 2, self.dial_diameter - awidth * 2, st + awidth / 2.0 - self.tic_width, en + awidth / 2.0), width=awidth, cap='none', joint='round')) if self.semi_circle: self.annular_canvas.add(PopMatrix()) self.canvas.before.add(self.annular_canvas)
def draw_ticks(self): scangle = self.angle_stop - self.angle_start inc = scangle / ( (self.scale_max - self.scale_min) / self.scale_increment) inc /= self.tic_frequency cnt = 0 # create an instruction group so we can remove it and recall draw_ticks to update when pos or size changes self.ticks = InstructionGroup() self.ticks.add(Color(*self.tic_color)) labi = self.scale_min x = -180.0 + self.angle_start + self.angle_offset # start while x <= self.angle_stop - 180 + self.angle_offset: a = x if (x < 0.0) else x + 360.0 need_label = True ticlen = self.tic_length if (cnt % self.tic_frequency != 0): ticlen = self.tic_length / 2 need_label = False cnt += 1 self.ticks.add(PushMatrix()) self.ticks.add( Rotate(angle=a, axis=(0, 0, -1), origin=(self.dial_center[0], self.dial_center[1]))) self.ticks.add(Translate(0, self.tic_radius - ticlen)) self.ticks.add( Line(points=[ self.dial_center[0], self.dial_center[1], self.dial_center[0], self.dial_center[1] + ticlen ], width=self.tic_width, cap='none', joint='none')) if need_label: #print("label: " + str(labi)) #kw['font_size'] = self.tic_length * 2 label = CoreLabel(text=str(int(round(labi))), font_size=self.scale_font_size) label.refresh() texture = label.texture self.ticks.add( Translate(-texture.size[0] / 2, -texture.size[1] - 2)) self.ticks.add( Rectangle(texture=texture, pos=self.dial_center, size=texture.size)) labi += self.scale_increment self.ticks.add(PopMatrix()) x += inc self.canvas.add(self.ticks)
def show_lines(self): indices = [] grid = self.grid cols = grid.cols rows = grid.rows for col in range(grid.cols + 1): indices.extend(( col * (rows + 1), col * (rows + 1) + rows, )) for row in range(grid.rows + 1): indices.extend(( row, row + (cols * (rows + 1)), )) with self.canvas: self.g_canvas = Canvas() with self.g_canvas: Color(1, 0, 0, 0.5) PushMatrix() Scale(self.width, self.height, 1.) self.g_mesh = Mesh(vertices=self.grid.line_vertices, indices=self.grid.line_indices, mode="lines", source="projectionmapping/data/white.png") PopMatrix() self.rebuild_informations()
def __init__(self, pos, tick): super(Trail, self).__init__() self.pos = pos self.tick = tick self.x = NOW_X + DRAW_CALIBRATION + tick * PIXELS_PER_TICK self.y = 360 - 240 + 480 * (pos) self.is_hit = False self.color = Color(rgb=[0.9, 0.9, 1.0], a=0.9) self.width = 40 * PIXELS_PER_TICK self.height = 20 self.flare_color = Color(rgb=[0.5, 0.5, 0.6]) self.flare_color.a = 0 self.hit_flare = Rectangle(pos=(self.x, self.y - 40), size=(20, 80)) self.add(self.flare_color) self.add(self.hit_flare) self.add(self.color) self.shape = Rectangle(pos=(-10, -10), size=(20, 20)) self.add(PushMatrix()) self.add(Translate(self.x, self.y)) self.add(Rotate(angle=45)) self.add(self.shape) self.add(PopMatrix())
def _render(self): if self.num_particles == 0: return for i in range(self.num_particles): particle = self.particles[i] size = (self.texture.size[0] * particle.scale, self.texture.size[1] * particle.scale) if particle not in self.particles_dict: self.particles_dict[particle] = dict() color = particle.color[:] with self.canvas: PushMatrix() self.particles_dict[particle]['color'] = Color( color[0], color[1], color[2], color[3]) self.particles_dict[particle]['translate'] = Translate() self.particles_dict[particle]['rotate'] = Rotate() self.particles_dict[particle]['rotate'].set( particle.rotation, 0, 0, 1) self.particles_dict[particle]['rect'] = Quad( texture=self.texture, points=(-size[0] * 0.5, -size[1] * 0.5, size[0] * 0.5, -size[1] * 0.5, size[0] * 0.5, size[1] * 0.5, -size[0] * 0.5, size[1] * 0.5)) self.particles_dict[particle]['translate'].xy = ( particle.x, particle.y) PopMatrix() else: self.particles_dict[particle][ 'rotate'].angle = particle.rotation self.particles_dict[particle]['translate'].xy = (particle.x, particle.y) self.particles_dict[particle]['color'].rgba = particle.color
def __init__(self, cpos, dim, shape): super().__init__() self.shape = shape tex_file = 'res/background/%s%d.png' % (self.shape, randint(1, 4)) self.buffer = dim[1] / 2 self.dim = np.array(dim, dtype=np.float) self.cpos = cpos self.pos = np.array([cpos[0] - 0.5 * dim[0], cpos[1] - 0.5 * dim[1]]) self.vel = np.array((choice([-1, 1]) * randint(50, 200), choice([-1, 1]) * randint(50, 200)), dtype=np.float) self.add(PushMatrix()) self.rotate = Rotate(origin=self.pos, angle=randint(0, 359)) self.add(self.rotate) self.shape = Rectangle(size=dim, texture=Image(tex_file).texture, pos=self.pos) self.add(self.shape) self.add(PopMatrix()) self.time = 0 self.on_update(0)
def draw_mesh(self, star_list): star_tex = Image('star1.png').texture vertex_format = [ (b'vPosition', 2, 'float'), (b'vSize', 1, 'float'), (b'vRotation', 1, 'float'), ] indices = [] ia = indices.append for star_number in range(len(star_list)): ia(star_number) vertices = [] e = vertices.extend for star in star_list: e([star[0], star[1], star[2], star[3]]) if self.mesh == None: with self.canvas: PushMatrix() self.mesh = Mesh(indices=indices, vertices=vertices, fmt=vertex_format, mode='points', texture=star_tex) PopMatrix() else: self.mesh.indices = indices self.mesh.vertices = vertices
def on_linecolor(self, *args): """If I don't yet have the instructions for drawing the selection box in my canvas, put them there. In any case, set the :class:`Color` instruction to match my current ``linecolor``. """ if hasattr(self, 'color'): self.color.rgba = self.linecolor return def upd_box_translate(*args): self.box_translate.xy = self.pos def upd_box_points(*args): self.box.points = [ 0, 0, self.width, 0, self.width, self.height, 0, self.height, 0, 0 ] self.boxgrp = boxgrp = InstructionGroup() self.color = Color(*self.linecolor) self.box_translate = Translate(*self.pos) boxgrp.add(PushMatrix()) boxgrp.add(self.box_translate) boxgrp.add(self.color) self.box = Line() upd_box_points() self.bind(size=upd_box_points, pos=upd_box_translate) boxgrp.add(self.box) boxgrp.add(Color(1., 1., 1.)) boxgrp.add(PopMatrix())
def draw_mesh(self, star_list): address = 'assets/particles/' tex_choice = choice([ 'particle.png', 'smokeparticle.png', 'VFX-0-Circle.png', 'VFX-0-Star.png', 'VFX-1-Star.png' ]) tex = Image(address + tex_choice).texture vertex_format = [(b'vPosition', 2, 'float'), (b'vSize', 1, 'float'), (b'vRotation', 1, 'float'), (b'vColor', 4, 'float')] indices = [] ia = indices.append for star_number in range(len(star_list)): ia(star_number) vertices = [] e = vertices.extend for star in star_list: color = star[4] e([ star[0], star[1], star[2], star[3], color[0], color[1], color[2], color[3] ]) if self.mesh == None: with self.canvas: PushMatrix() self.mesh = Mesh(indices=indices, vertices=vertices, fmt=vertex_format, mode='points', texture=tex) PopMatrix() else: self.mesh.indices = indices self.mesh.vertices = vertices self.mesh.texture = tex
def __init__(self, parent, **kwargs): super(Ball, self).__init__(**kwargs) self.touch_uid = None self.target_pos = self.pos self.animation = None radius = self.radius = parent.cell_size * 0.3 self.handle_radius = parent.cell_size * BALL_TOUCH_RADIUS self.zoc_radius = self.radius with self.canvas: Color(0, 0, 1, 0.5) Ellipse(pos=(-radius, -radius), size=(radius * 2, radius * 2)) Color(0, 0, 0, 1) HollowCircle((0, 0), radius, 18) Color(0.5, 0.5, 0.5, 0.4) FilledCircle((0, 0), self.handle_radius) HollowCircle((0, 0), self.handle_radius, 18) self.scale_instruction = Scale(self.zoc_radius) Color(1, 1, 1, 0.2) FilledCircle((0, 0), 1) Color(0.5, 0.5, 0.5, 0.4) HollowCircle((0, 0), 1, 32) with self.canvas.before: PushMatrix() self.translation_instruction = Translate(0, 0, 0) with self.canvas.after: PopMatrix()
def on_update(self): self.animations.on_update() self.actual_sound.on_update() self.user_sound.on_update() self.key_label.set_text(f"Key: {self.user_key}") if not self.game_over and self.is_game_over(): for pos, obj in self.objects.items(): if isinstance(obj, MovingBlock): obj.moveable = False if self.level == max(levels.keys()): self.on_finished_puzzle() self.on_game_over() else: if (-1, 4) not in self.objects: size = (self.grid.tile_side_len, self.grid.tile_side_len) self.objects[(-1, 4)] = DoorTile( size, self.grid.grid_to_pixel((-1, 4)), PianoPuzzle, source=self.door_sources[(-1, 4)], ) self.add(PushMatrix()) self.add(Translate(*self.grid.pos)) self.add(self.objects[(-1, 4)]) self.add(PopMatrix())
def place_objects(self): # rhythm_color = Color(rgba=(0, 0.5, 0.5, 1)) for i in range(len(durations)): # rhythm self.grid.get_tile( (i + 3, 2)).set_color(color=Tile.base_color, source="./data/trackv2.png") # pitch_color = Color(rgba=(0.2, 0.5, 1, 1)) for i in range(7): # rhythm self.grid.get_tile( (i + 1, 7)).set_color(color=Tile.base_color, source="./data/trackv2.png") # key_color = Color(rgba=(0.2, 0.5, 0, 1)) for i in range(len(key_names)): self.grid.get_tile( (i + 1, 5)).set_color(color=Tile.base_color, source="./data/trackv2.png") self.add(PushMatrix()) self.add(Translate(*self.grid.pos)) for pos, obj in self.objects.items(): self.add(obj) self.add(PopMatrix())
def __init__(self, color, pos): super(SingularKaleidoscope, self).__init__() offset = Window.width * 0.05 self.height = Window.height / 3 self.add(PushMatrix()) self.background = CRectangle( pos=pos, size=(0, 0), texture=Image('res/kaleidoscope/bw-circle.png').texture) self.add(self.background) self.rotate = Rotate(angle=0, origin=pos) self.add(self.rotate) self.star = CRectangle( pos=pos, size=(0, 0), texture=Image('res/kaleidoscope/bw-inner-star.png').texture) self.add(self.star) self.add(PopMatrix()) self.circle = CEllipse(cpos=pos, csize=(0, 0)) self.color = Color(*color) self.color.a = 0.5 self.add(self.color) self.add(self.circle) self.size_grow = None
def _get_fbo(self,widget): '''get frame buffer object of widget. Args: widget: subclass of kivy.uix.widget. Returns: kivy.graphics.fbo ''' if widget.parent is not None: canvas_parent_index = widget.parent.canvas.indexof(self.canvas) if canvas_parent_index > -1: widget.parent.canvas.remove(widget.canvas) fbo = Fbo(size=widget.size, with_stencilbuffer=True) with fbo: PushMatrix() ClearColor(0, 0, 0, 0) ClearBuffers() Scale(1, -1, 1) Translate(-widget.x, -widget.y - widget.height, 0) Rotate(origin=widget.center, axis=(widget.center_x,0,0), angle=-180) return fbo
def create_instructions(self): margin = self.grid.tile_side_len // 2 self.instructions_window_color = Color(rgba=(1, 1, 1, 1)) self.instructions_window = Rectangle( pos=(margin, margin), size=( self.grid.grid_side_len - 2 * margin - 2 * self.grid.tile_side_len, 3 * self.grid.tile_side_len - 2 * margin, ), ) self.instructions_text_color = Color(rgba=(0, 0, 0, 1)) self.instructions_text = CLabelRect( (self.win_size[0] // 2, self.win_size[1] // 4.3), "Move around the room with the arrow keys\n" + "Press 'a' to interact with objects", 34, ) self.add(PushMatrix()) self.add(Translate(*self.grid.pos)) self.add(self.instructions_window_color) self.add(self.instructions_window) self.add(PopMatrix()) self.add(self.instructions_text_color) self.add(self.instructions_text)
def draw(self): Game.engine['gfx'].draw_rectangle( (self.x, self.y), (self.width, self.height), self.current_colour) # Kivy is special so we make sure that our attached widget is the right colour and size # to get the overlay to appear if Game.engine_def['gfx'] == "kivy": from kivy.graphics import Color, PushMatrix, PopMatrix, Translate, Quad if not self in Game.engine['gfx'].entity_draws: Game.engine['gfx'].entity_draws[self] = dict() with Game.engine['gfx'].widget.canvas: Game.engine['gfx'].entity_draws[self]['color'] = Color() Game.engine['gfx'].entity_draws[self][ 'color'].rgba = self.current_colour PushMatrix() Game.engine['gfx'].entity_draws[self][ 'translate'] = Translate() Game.engine['gfx'].entity_draws[self]['rect'] = Quad( points=(0.0, 0.0, self.width, 0.0, self.width, self.height, 0.0, self.height)) Game.engine['gfx'].entity_draws[self]['translate'].xy = ( self.x, self.y) PopMatrix() # Otherwise just update values else: Game.engine['gfx'].entity_draws[self]['translate'].xy = ( self.x, self.y) Game.engine['gfx'].entity_draws[self][ 'color'].rgba = self.current_colour Game.engine['gfx'].entity_draws[self]['rect'].points = ( 0.0, 0.0, self.width, 0.0, self.width, self.height, 0.0, self.height)
def countdown(self, num): """The countdown for the solving player For positive `num`, shows the number near the maze entrance, animates it, and schedules a call to countdown(num-1) for one second. For num == 0, display 'Go!', animate it, and grow the ball source. """ label = Label( text=str(num) if num else 'Go!', font_size=24, color=(0, 0, 1, 1), ) with label.canvas.before: PushMatrix() Translate( self.window_width - self.cell_size * 1, self.window_height - self.cell_size * 5, 0, ) Rotate(90, 0, 0, 1) with label.canvas.after: PopMatrix() animation = Animation(font_size=256, color=(0, 0, 1, 0), t='in_cubic', duration=1.5) animation.start(label) self.add_widget(label) if num > 0: Clock.schedule_once(lambda dt: self.countdown(num - 1), 1) else: self.ball_source.grow(self.cell_size * 3) if self.parent: self.parent.set_message(True, u'Take a ball from the blue corner.')
def move_block(self, new_location, x, y): obj_loc = (new_location[0] + x, new_location[1] + y) if self.is_valid_pos(obj_loc) and self.valid_block_move( obj_loc, self.objects[new_location].move_range): self.remove(self.objects[new_location]) obj = MovingBlock( self.objects[new_location].size, self.grid.grid_to_pixel(obj_loc), self.objects[new_location].move_range, self.objects[new_location].color, self.objects[new_location].icon_source, self.objects[new_location].final_position, ) del self.objects[new_location] self.add(PushMatrix()) self.add(Translate(*self.grid.pos)) self.add(obj) self.add(PopMatrix()) self.objects[obj_loc] = obj self.blocks_placed += self.objects[obj_loc].on_block_placement( obj_loc) return True else: return False
def __init__(self, cpos, radius, texture=None): super(TimedCEllipse, self).__init__() # save position self.cpos = cpos self.r = radius self.width = radius * .2 # code for creating the Line self.rcolor = Color(*kGemRingColor, mode="rgba") self.rrgb = kGemRingColor PushMatrix() self.add(self.rcolor) self.angle = 0 self.ring = Line(circle=(*self.cpos, self.r, self.angle, 360), width=self.width, cap='none') self.add(self.ring) # code for creating the circle self.ccolor = Color(*kGemCircleColor) self.add(self.ccolor) csize = (2 * radius - self.width, ) * 2 self.circ = CEllipse(cpos=cpos, csize=csize) self.add(self.circ) PopMatrix()
def draw_ticks(self): self.ticks.clear() self.ticks.add(Color(*self.tick_color, mode='rgb')) self.ticks.add(PushMatrix()) self.ticks.add(self.tick_translate) if self.tick_distance_x is not None: first_x_tick = self.tick_distance_x * ( int(self.viewport[0] / self.tick_distance_x) + 1) for x in drange(first_x_tick, self.viewport[2], self.tick_distance_x): start = self.to_display_point(x, self.viewport[1]) stop = self.to_display_point(x, self.viewport[3]) self.ticks.add( Line(points=[start[0], start[1], stop[0], stop[1]])) if self.tick_distance_y is not None: first_y_tick = self.tick_distance_y * ( int(self.viewport[1] / self.tick_distance_y) + 1) for y in drange(first_y_tick, self.viewport[3], self.tick_distance_y): start = self.to_display_point(self.viewport[0], y) stop = self.to_display_point(self.viewport[2], y) self.ticks.add( Line(points=[start[0], start[1], stop[0], stop[1]])) self.ticks.add(PopMatrix())
def __init__(self, pos, color, angle): super(Note, self).__init__() self.pos = np.array(pos, dtype=np.float) self.pos[0] += 25 self.pos[1] += 10 self.color = Color(*color) self.add(self.color) # adds a translation and rotation and another translation to the note self.add(PushMatrix()) self.translate = Translate(*self.pos) self.add(self.translate) self._angle = Rotate(angle=angle) self.add(self._angle) self.translate2 = Translate(0, 40) self.add(self.translate2) self.note = Rectangle(texture=Image("particle/texture.png").texture, pos=(-15, -15), size=(30, 30)) self.add(self.note) self.add(PopMatrix()) self.vel = np.array((0, 60), dtype=np.float) self.color.a = 1
def __init__(self, filepath): super(Picture, self).__init__() im = Image.open(filepath).convert("RGBA") self.image = im.copy() self.temp = im.copy() self.filepath = filepath # Save states self.history = [(im, im.size[0], im.size[1])] # includes current state self.history_pos = 0 # Size and graphics width, height = self.image.size pos = (Window.width - width) // 2, (Window.height - height) // 2 size = (width, height) # allow rotation: self.add(PushMatrix()) self.rotate = Rotate(angle=0) self.add(self.rotate) # create rectangle to hold image self.rectangle = Rectangle(pos=pos, size=size) self.add(PopMatrix()) self.on_update() self.add(self.rectangle)
def __init__(self, **kwargs): # Make sure opengl context exists EventLoop.ensure_window() self.canvas = RenderContext(use_parent_projection=True, use_parent_modelview=True) with self.canvas: self.fbo = Fbo(size=self.size) with self.fbo.before: PushMatrix() self.fbo_translation = Translate(-self.x, -self.y, 0) with self.fbo: ClearColor(1, 1, 1, 1) Color(*self.background_color) ClearBuffers() self.fbo_rectangle = Rectangle(size=self.size) with self.fbo.after: PopMatrix() super(EffectWidget, self).__init__(**kwargs) Clock.schedule_interval(self._update_glsl, 0) self.bind(pos=self._update_translation, size=self.refresh_fbo_setup, effects=self.refresh_fbo_setup) self.refresh_fbo_setup()
def __init__(self, **kwargs): # Make sure opengl context exists EventLoop.ensure_window() self.canvas = RenderContext(use_parent_projection=True, use_parent_modelview=True) with self.canvas: self.fbo = Fbo(size=self.size) with self.fbo.before: PushMatrix() with self.fbo: ClearColor(0, 0, 0, 0) ClearBuffers() self._background_color = Color(*self.background_color) self.fbo_rectangle = Rectangle(size=self.size) with self.fbo.after: PopMatrix() super(EffectWidget, self).__init__(**kwargs) Clock.schedule_interval(self._update_glsl, 0) fbind = self.fbind fbo_setup = self.refresh_fbo_setup fbind('size', fbo_setup) fbind('effects', fbo_setup) fbind('background_color', self._refresh_background_color) self.refresh_fbo_setup() self._refresh_background_color() # In case thi was changed in kwargs
def draw_mesh(self, this_star_list): if self.this_op is None: self.this_op = PointRendererOp() star_tex = Image('star1.png').texture self.this_op.indices = [] ia = self.this_op.indices.append for star_number in range(len(this_star_list)): ia(star_number) self.this_op.vertices = [] e = self.this_op.vertices.extend for star in this_star_list: this_star = [ star[0], star[1], star[2], star[3], \ star[4], star[5], star[6], star[7] ] if len(this_star) != self.vertex_depth: print("FATAL ERROR: array size does not match " + \ "vertex depth (offset)") exit(1) e(this_star) if self.mesh == None: with self.canvas: PushMatrix() self.mesh = Mesh(indices=self.this_op.indices, vertices=self.this_op.vertices, fmt=self.vertex_format, mode='points', texture=star_tex) PopMatrix() else: # self.mesh.indices = self.this_op.indices self.mesh.vertices = self.this_op.vertices pass