Example #1
0
    def background(self, cr: cairo.Context):

        linear = cairo.LinearGradient(0, 0, .25, 1)
        linear.add_color_stop_rgb(0.0, *colors[0])
        linear.add_color_stop_rgb(0.4, *colors[5])
        linear.add_color_stop_rgb(1.0, *colors[6])

        cr.rectangle(0, 0, .5, 1)
        cr.set_source(linear)
        cr.fill()

        cr.rectangle(0.5, 0, 1, 1)

        linear = cairo.LinearGradient(1, 0, .75, 1)
        linear.add_color_stop_rgb(0.0, *colors[0])
        linear.add_color_stop_rgb(0.4, *colors[5])
        linear.add_color_stop_rgb(1.0, *colors[6])
        cr.set_source(linear)
        cr.fill()

        cr.move_to(.5, 0)  # lower left
        cr.rel_line_to(-.5, 1)
        cr.rel_line_to(1, 0)
        cr.close_path()

        radial = cairo.RadialGradient(0.5, 0.5, 0.1, 0.5, 0.5, 0.75)
        radial.add_color_stop_rgba(0, *colors[3], 0.7)
        radial.add_color_stop_rgba(.4, *colors[1], 0.5)
        radial.add_color_stop_rgba(1, *colors[2], 0.1)

        cr.set_source(radial)
        cr.fill()
Example #2
0
    def _append_hand_path(self, cr: cairo.Context, pos: Vector2[float],
                          angle: float, radius: float) -> None:
        if radius == 0:
            return

        cr.move_to(*pos)
        cr.rel_line_to(radius * math.cos(angle), radius * math.sin(angle))
Example #3
0
    def draw_triag(self, cr: cairo.Context, p):
        # p-> lower left coordinate of the triangle
        cr.move_to(*p)  # lower left

        cr.rel_line_to(2 * self.dx, 0)  # line to lower right
        cr.rel_line_to(-self.dx, -self.dy)
        cr.close_path()
Example #4
0
def draw_player(cr: cairo.Context, player: Player) -> None:
    with save_context(cr):
        cr.translate(player.x, player.y)

        with save_context(cr):
            cr.rotate(player.rotation)

            # draw player
            cr.set_source_rgb(0, 0, 0)
            cr.arc(0, 0, 10, 0, math.tau)
            cr.fill()

            # draw arms
            cr.move_to(2, -10)
            cr.rel_line_to(12, 0)
            cr.move_to(2, 10)
            cr.rel_line_to(12, 0)
            cr.stroke()

        # draw health
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(-20, -35, 40, 8)
        cr.fill()
        # cr.set_source_rgb(.1, .9, .2)
        cr.set_source_rgb(2 * (1 - player.health), 2 * player.health, 0)
        cr.rectangle(-20, -35, 40 * player.health, 8)
        cr.fill()
        cr.set_line_width(1)
        cr.set_source_rgb(0, 0, 0)
        cr.rectangle(-20, -35, 40, 8)
        cr.stroke()
    def do_render(self, model: Dazzle.GraphModel, x_begin: int, x_end: int,
                  y_begin: float, y_end: float, cairo_context: cairo.Context,
                  area: cairo.RectangleInt) -> None:
        model_iter = Dazzle.GraphModelIter()
        cairo_context.save()

        if model.get_iter_first(model_iter):
            chunk = area.width / (model.props.max_samples - 1) / 2.0
            last_x = self._calc_x(model_iter, x_begin, x_end, area.width)
            last_y = float(area.height)

            cairo_context.move_to(last_x, area.height)

            while Dazzle.GraphModel.iter_next(model_iter):
                x = self._calc_x(model_iter, x_begin, x_end, area.width)
                y = self._calc_y(model_iter, y_begin, y_end, area.height,
                                 self._column)

                cairo_context.curve_to(last_x + chunk, last_y, last_x + chunk,
                                       y, x, y)

                last_x = x
                last_y = y

        cairo_context.set_line_width(self._line_width)
        cairo_context.set_source_rgba(self._stacked_color_rgba.red,
                                      self._stacked_color_rgba.green,
                                      self._stacked_color_rgba.blue,
                                      self._stacked_color_rgba.alpha)
        cairo_context.rel_line_to(0, area.height)
        cairo_context.stroke_preserve()
        cairo_context.close_path()
        cairo_context.fill()

        if model.get_iter_first(model_iter):
            chunk = area.width / (model.props.max_samples - 1) / 2.0
            last_x = self._calc_x(model_iter, x_begin, x_end, area.width)
            last_y = float(area.height)

            cairo_context.move_to(last_x, last_y)

            while Dazzle.GraphModel.iter_next(model_iter):
                x = self._calc_x(model_iter, x_begin, x_end, area.width)
                y = self._calc_y(model_iter, y_begin, y_end, area.height,
                                 self._column)

                cairo_context.curve_to(last_x + chunk, last_y, last_x + chunk,
                                       y, x, y)

                last_x = x
                last_y = y

        cairo_context.set_source_rgba(self._stroke_color_rgba.red,
                                      self._stroke_color_rgba.green,
                                      self._stroke_color_rgba.blue,
                                      self._stacked_color_rgba.alpha)
        cairo_context.stroke()
        cairo_context.restore()
Example #6
0
 def _draw_plus(self, ctx: cairo.Context):
     arrow_len = BPC_TILE_DIM / 4
     ctx.set_source_rgb(1, 1, 1)
     ctx.translate(-arrow_len, 0)
     ctx.move_to(0, 0)
     ctx.rel_line_to(arrow_len * 2, 0)
     ctx.stroke()
     ctx.translate(arrow_len, -arrow_len)
     ctx.move_to(0, 0)
     ctx.rel_line_to(0, arrow_len * 2)
     ctx.stroke()
     ctx.translate(0, arrow_len)
Example #7
0
def cross(ctx: cairo.Context,
          span: float,
          tblr=['up', 'down', 'left', 'right']) -> None:
    if 'up' in tblr:
        ctx.rel_move_to(0, -span / 2)
        ctx.rel_line_to(0, span / 2)
    if 'down' in tblr:
        ctx.rel_move_to(0, span / 2)
        ctx.rel_line_to(0, -span / 2)
    if 'left' in tblr:
        ctx.rel_move_to(-span / 2, 0)
        ctx.rel_line_to(span / 2, 0)
    if 'right' in tblr:
        ctx.rel_move_to(span / 2, 0)
        ctx.rel_line_to(-span / 2, 0)
Example #8
0
def arrowhead(context: cairo.Context,
              size: float,
              position: Point,
              direction: Point = None,
              front_angle: float = math.pi / 4,
              back_angle: float = math.pi / 2):
    '''Add an arrow head to the current path, starting at the current point.'''
    if direction is None:
        direction = Point(0, 1)
    halfwidth = math.tan(front_angle / 2) * size
    back_height = halfwidth / math.tan(back_angle / 2)

    context.move_to(*position)
    context.rotate(-math.atan2(direction.x, direction.y))
    context.rel_line_to(halfwidth, -back_height)
    context.rel_line_to(-halfwidth, size)
    context.rel_line_to(-halfwidth, -size)
    context.fill()
Example #9
0
 def _show_hand(self, cr: cairo.Context, x: float, y: float, angle: float, radius: float) -> None:
     if radius == 0.0:
         return
     cr.move_to(x, y)
     cr.rel_line_to(radius * math.cos(angle), radius * math.sin(angle))
     cr.new_sub_path()
Example #10
0
def flap_border(ctx: cairo.Context, width: float, half_h: float) -> None:
    ctx.rel_line_to(width, 0)
    ctx.rel_line_to(0, 2 * half_h)
    ctx.rel_line_to(-width, 0)
    ctx.rel_line_to(0, -2 * half_h)