Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    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()
Ejemplo n.º 5
0
    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())
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    def __init__(self, pos, texture, size_x=1.0, size_y=1.0, intensity=1.0, Tr=1.0):
        super(BillboardDisplay, self).__init__()
        
        self.intensity = intensity
        self.Tr = Tr

        self.translate = Translate()
        self.rotate_azi = Rotate(origin=(0,0,0), axis=(0,1,0))
        self.rotate_ele = Rotate(origin=(0,0,0), axis=(1,0,0))
        self.scale = Scale()
        self.color_instruction = InstructionGroup()
        self.mesh = Mesh(
            texture=texture,
            vertices=rectangle_nurb.vertices,
            indices=rectangle_nurb.indices,
            fmt=rectangle_nurb.vertex_format,
            mode='triangles'
        )

        self.add(PushMatrix())
        self.add(self.translate)
        self.add(self.rotate_azi)
        self.add(self.rotate_ele)
        self.add(self.scale)
        self.add(self.color_instruction)
        self.add(self.mesh)
        self.add(PopMatrix())

        self.set_color(intensity=intensity, Tr=Tr)
        self.set_size(size_x, size_y)
        self.set_pos(pos)
        self.set_texture(texture)
Ejemplo n.º 8
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
Ejemplo n.º 9
0
    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()
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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())
Ejemplo n.º 13
0
 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())
Ejemplo n.º 14
0
    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
Ejemplo n.º 15
0
    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
Ejemplo n.º 16
0
    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.')
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
 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
Ejemplo n.º 19
0
    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)
Ejemplo n.º 20
0
    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())
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
    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)
Ejemplo n.º 23
0
    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
Ejemplo n.º 24
0
    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()
Ejemplo n.º 25
0
    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())
Ejemplo n.º 26
0
    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()
Ejemplo n.º 27
0
    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)
Ejemplo n.º 28
0
    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
Ejemplo n.º 29
0
    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
Ejemplo n.º 30
0
    def __init__(self,
                 nurb,
                 pos,
                 size=1.0,
                 color=(0.0, 1.0, 0.0),
                 tr=1.0,
                 intensity=1.0):
        super(NurbDisplay, self).__init__()

        self.color = color
        self.tr = tr
        self.intensity = intensity

        self.translate = Translate()
        self.scale = Scale()
        self.color_instruction = InstructionGroup()

        self.add(PushMatrix())
        self.add(self.translate)
        self.add(self.scale)
        self.add(self.color_instruction)
        self.add(self.make_mesh(nurb))
        self.add(PopMatrix())

        self.set_color()
        self.set_size(size)
        self.set_pos(pos)