Exemplo n.º 1
0
        def drawPoint(x, y):
            rect = Rectangle(self.bounds.x + x * self.tileSize,
                             self.bounds.y + y * self.tileSize,
                             self.tileSize, self.tileSize)
            tile = self.maze.map[x][y]
            background_color = self.EMPTY_COLOR
            if tile == self.maze.EMPTY:
                background_color = self.EMPTY_COLOR
            elif tile == self.maze.SOLID:
                background_color = self.SOLID_COLOR
            elif tile == self.maze.GOAL:
                background_color = self.GOAL_COLOR
            self._ctx.save()
            self._ctx.set_source_rgb(*background_color)
            self._ctx.rectangle(*rect.get_bounds())
            self._ctx.fill()

            if self._show_trail:
                if tile == self.maze.SEEN:
                    radius = self.tileSize / 3 - self.outline
                    center = self.tileSize / 2
                    self._ctx.set_source_rgba(
                        *self.localplayers[0].bg.get_rgba())
                    self._ctx.arc(rect.x + center, rect.y + center, radius, 0,
                                  2 * pi)
                    self._ctx.fill()
            self._ctx.restore()
Exemplo n.º 2
0
        def drawPoint(x, y):
            rect = Rectangle(self.bounds.x + x * self.tileSize,
                             self.bounds.y + y * self.tileSize,
                             self.tileSize, self.tileSize)
            tile = self.maze.map[x][y]
            background_color = self.EMPTY_COLOR
            if tile == self.maze.EMPTY:
                background_color = self.EMPTY_COLOR
            elif tile == self.maze.SOLID:
                background_color = self.SOLID_COLOR
            elif tile == self.maze.GOAL:
                background_color = self.GOAL_COLOR
            self._ctx.save()
            self._ctx.set_source_rgb(*background_color)
            self._ctx.rectangle(*rect.get_bounds())
            self._ctx.fill()

            if self._show_trail:
                if tile == self.maze.SEEN:
                    radius = self.tileSize / 3 - self.outline
                    center = self.tileSize / 2
                    self._ctx.set_source_rgba(
                        *self.localplayers[0].bg.get_rgba())
                    self._ctx.arc(rect.x + center, rect.y + center, radius, 0,
                                  2 * pi)
                    self._ctx.fill()
            self._ctx.restore()
Exemplo n.º 3
0
 def _mark_point_dirty(self, pt):
     """ Mark a maze point that needs to be redrawn,
         and ask GTK to redraw the widget in that area. """
     self._dirty_points.append(pt)
     rect = Rectangle(self.bounds.x + pt[0] * self.tileSize,
                      self.bounds.y + pt[1] * self.tileSize, self.tileSize,
                      self.tileSize)
     self.queue_draw_area(rect.x, rect.y, rect.width, rect.height)
Exemplo n.º 4
0
        def drawPoint(x, y):
            rect = Rectangle(self.bounds.x + x * self.tileSize,
                             self.bounds.y + y * self.tileSize, self.tileSize,
                             self.tileSize)
            tile = self.maze.map[x][y]

            if tile == self.maze.HOLE:
                line_width = self.tileSize / 32.
                center = self.tileSize / 2
                self._ctx.save()
                self._ctx.set_source_rgb(*self.EMPTY_COLOR)
                self._ctx.rectangle(*rect.get_bounds())
                self._ctx.fill()
                self._ctx.arc(rect.x + center, rect.y + center,
                              center - line_width, 0, 2 * pi)
                self._ctx.save()
                self._ctx.set_source_rgb(*self.HOLE_COLOR)
                self._ctx.set_line_width(line_width)
                self._ctx.fill_preserve()
                self._ctx.set_source_rgba(*self.SOLID_COLOR)
                self._ctx.stroke()
            else:
                bg = {
                    self.maze.SOLID: self.SOLID_COLOR,
                    self.maze.EMPTY: self.EMPTY_COLOR,
                    self.maze.SEEN: self.EMPTY_COLOR,
                    self.maze.GOAL: self.GOAL_COLOR,
                    self.maze.PASSED: self.PASSED_COLOR
                }
                self._ctx.save()
                self._ctx.set_source_rgb(*bg[tile])
                self._ctx.rectangle(*rect.get_bounds())
                self._ctx.fill()

            if self._show_trail:
                if tile == self.maze.SEEN:
                    radius = self.tileSize / 3 - self.outline
                    center = self.tileSize / 2
                    self._ctx.set_source_rgba(
                        *self.localplayers[0].bg.get_rgba())
                    self._ctx.arc(rect.x + center, rect.y + center, radius, 0,
                                  2 * pi)
                    self._ctx.fill()
            self._ctx.restore()
Exemplo n.º 5
0
 def _recalculate_sizes(self, allocation):
     self._width = allocation.width
     self._height = allocation.height
     # compute the size of the tiles given the screen size, etc.
     self.tileSize = min(self._width // self.maze.width,
                         self._height // self.maze.height)
     self.bounds = Rectangle(
         (self._width - self.tileSize * self.maze.width) // 2,
         (self._height - self.tileSize * self.maze.height) // 2,
         self.tileSize * self.maze.width, self.tileSize * self.maze.height)
     self.outline = int(self.tileSize / 5)
     self._cached_surface = None
     self.queue_draw()
     self._dirty_rect = self.maze.bounds
Exemplo n.º 6
0
    def draw(self, ctx, bounds, size):
        line_width = size / 32.
        rect = Rectangle(bounds.x + self.position[0] * size,
                         bounds.y + self.position[1] * size, size, size)

        ctx.save()

        # centre of face
        cx = rect.x + size / 2
        cy = rect.y + size / 2

        bg = {
            'centre': self.bg.get_rgba(),
            'left': [0.45, 0.45, 0.45, 1.],
            'right': [0.55, 0.55, 0.55, 1.]
        }
        fg = {
            'centre': self.fg.get_rgba(),
            'left': [1., 1., 1., 1.],
            'right': [0., 0., 0., 1.]
        }

        # a background filled circle with foreground border
        ctx.arc(cx, cy, (size / 2 - line_width), 0, 2 * math.pi)
        ctx.set_source_rgba(*bg[self.look])
        ctx.set_line_width(line_width)
        ctx.fill_preserve()
        ctx.set_source_rgba(*fg[self.look])
        ctx.stroke()

        # two eyes
        for ex in [cx - 0.20 * size, cx + 0.20 * size]:
            # conjunctiva
            er = 0.14 * size
            ey = cy - 0.05 * size
            ctx.arc(ex, ey, er, 0, 2 * math.pi)
            ctx.set_source_rgba(1., 1., 1., 1.)
            ctx.fill()
            # iris, pupil
            er = 0.04 * size
            if self.look == 'left':
                ex -= 0.04 * size
            elif self.look == 'right':
                ex += 0.04 * size
            else:
                ey += 0.02 * size
            ctx.arc(ex, ey, er, 0, 2 * math.pi)
            ctx.set_source_rgba(0., 0., 0., 1.)
            ctx.fill()

        # mouth
        (lx, ly) = (cx - 0.25 * size, cy + 0.15 * size)  # left corner
        (bx, by) = (cx, cy + 0.25 * size)  # weak control
        (rx, ry) = (cx + 0.25 * size, cy + 0.15 * size)  # right corner
        (tx, ty) = (cx, cy + 0.50 * size)  # strong control
        ctx.set_source_rgba(1., 1., 1., 1.)
        ctx.curve_to(lx, ly, bx, by, rx, ry)  # upper lip
        ctx.curve_to(rx, ry, tx, ty, lx, ly)  # lower lip
        ctx.fill_preserve()
        ctx.stroke()

        ctx.restore()