Exemplo n.º 1
0
 def bezier(self, points, steps, color=Color.DEFAULT, alpha=-1):
     """
     Draw a bezier _curve based on a control point and a number of steps
     :param points:
     :param steps:
     :param color:
     :param alpha:
     :return:
     """
     gfxdraw.bezier(self._surface, points, steps,
                    self._csv_rgb2sdl_color(color, alpha))
Exemplo n.º 2
0
def double_wave(surface, progress, mood):
    width, height = surface.get_size()
    w = width // 40
    for i in range(w):
        bezier(surface, [
            (int((-progress+0.25) % 1 * width), height // 2 + i),
            (int((-progress+0.25) % 1 * width + width / 2), i),
            (int((-progress+0.25) % 1 * width + width / 2), height + i),
            (int((-progress+0.25) % 1 * width + width), height // 2 + i)
        ], 16, mood.secondary_color)
        bezier(surface, [
            (int((-progress+0.25) % 1 * width - width), height // 2 + i),
            (int((-progress+0.25) % 1 * width - width / 2), i),
            (int((-progress+0.25) % 1 * width - width / 2), height + i),
            (int((-progress+0.25) % 1 * width), height // 2 + i)
        ], 16, mood.secondary_color)
    for i in range(w):
        bezier(surface, [
            (int(progress * width), height // 2 + i),
            (int(progress * width + width / 2), i),
            (int(progress * width + width / 2), height + i),
            (int(progress * width + width), height // 2 + i)
        ], 16, mood.primary_color)
        bezier(surface, [
            (int(progress * width - width), height // 2 + i),
            (int(progress * width - width / 2), i),
            (int(progress * width - width / 2), height + i),
            (int(progress * width), height // 2 + i)
        ], 16, mood.primary_color)
Exemplo n.º 3
0
def Draw(surface: pygame.Surface,
         list_points,
         color_code: tuple,
         type: str,
         font=None,
         int=None):
    if type == "line":
        gfxdraw.line(surface, list_points[0], list_points[1], list_points[2],
                     list_points[3], color_code)
    if type == "bezier":
        gfxdraw.bezier(surface, list_points, 4500, color_code)
    if type == "dot":
        gfxdraw.filled_circle(surface, list_points[0], list_points[1], 5,
                              color_code)
        surface.blit(font.render(str(int), True, color_code), list_points)
Exemplo n.º 4
0
def wave(surface, pos):
    width, height = surface.get_size()
    w = width // 40
    color = (int(max(0.0, sin(pos * 2 * pi)) * 255),
             int(max(0.0, sin(pos * 2 * pi + pi * 2 / 3)) * 255),
             int(max(0.0, sin(pos * 2 * pi + pi * 4 / 3)) * 255))
    for i in range(w):
        bezier(surface, [(int(pos * width), height // 2 + i),
                         (int(pos * width + width / 2), i),
                         (int(pos * width + width / 2), height + i),
                         (int(pos * width + width), height // 2 + i)], 16,
               color)
        bezier(surface, [(int(pos * width - width), height // 2 + i),
                         (int(pos * width - width / 2), i),
                         (int(pos * width - width / 2), height + i),
                         (int(pos * width), height // 2 + i)], 16, color)
Exemplo n.º 5
0
    def render(self, pos, dt):
        dirties = []
        # if self.zoom == "galaxy":
        if self.zoom == "solar" or self.zoom == "sector":
            self.layer.sprites.clear(self.screen, self.background)
            if self.zoom == "sector":
                for points in self.layer.get_points_from_connections(pos):
                    gfxdraw.bezier(self.screen, points, 10, (255, 0, 0))
            # pos = self.camera.state.centerx - self.layer.dimensions.w /2, self.camera.state.centery - self.layer.dimensions.h /2
            self.layer.sprites.update(pos, dt)  # self.camera,
            dirties.append(self.layer.sprites.draw(self.screen))
        else:
            self.sprites.clear(self.screen, self.background)
            self.sprites.update(pos, dt)

        self.sprites.update(pos, dt)
        self.ui_overlay.update(pos, dt)
        return dirties
Exemplo n.º 6
0
    def bezier(self, points, steps, color):
        """ベジェ曲線を描画します.

        Parameters
        ----------
        pointlist : array-like
            ベジェ曲線の制御点の座標を格納した2次元配列.
            配列の2次元目の要素数は2で, 少なくとも2点以上の座標を設定する必要があります.
        steps : tuple of int
            ベジェ曲線の次数を指定します.
        closed : bool
            Trueに設定された場合, 始点と終点を直線でつないで描画します.

        """

        return gfx.bezier(self.pg.screen, points, steps, color)
Exemplo n.º 7
0
    def _draw(self, deco: List[Tuple[int, str, Any]], surface: 'pygame.Surface') -> None:
        """
        Draw.

        :param deco: Decoration list
        :param surface: Pygame surface
        :return: None
        """
        if len(deco) == 0:
            return
        rect = self._obj.get_rect()

        for d in deco:
            dtype, decoid, data = d
            if not self._decor_enabled[decoid]:
                continue

            if dtype == DECORATION_POLYGON:
                points, color, filled, width, gfx, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                if gfx:
                    if filled:
                        gfxdraw.filled_polygon(surface, points, color)
                    else:
                        gfxdraw.polygon(surface, points, color)
                else:
                    pydraw.polygon(surface, color, points, width)

            elif dtype == DECORATION_CIRCLE:
                points, r, color, filled, width, gfx, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                x, y = points[0]
                if filled:
                    if gfx:
                        gfxdraw.filled_circle(surface, x, y, r, color)
                    else:
                        pydraw.circle(surface, color, (x, y), r)
                else:
                    pydraw.circle(surface, color, (x, y), r, width)

            elif dtype == DECORATION_SURFACE or dtype == DECORATION_BASEIMAGE or dtype == DECORATION_TEXT:
                pos, surf, centered, kwargs = data
                if isinstance(surf, pygame_menu.BaseImage):
                    surf = surf.get_surface(new=False)
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0]
                surfrect = surf.get_rect()
                surfrect.x += pos[0]
                surfrect.y += pos[1]
                if centered:
                    surfrect.x -= surfrect.width / 2
                    surfrect.y -= surfrect.height / 2
                surface.blit(surf, surfrect)

            elif dtype == DECORATION_ELLIPSE:
                pos, rx, ry, color, filled, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0]
                if filled:
                    gfxdraw.filled_ellipse(surface, pos[0], pos[1], rx, ry, color)
                else:
                    gfxdraw.ellipse(surface, pos[0], pos[1], rx, ry, color)

            elif dtype == DECORATION_CALLABLE:
                data(surface, self._obj)

            elif dtype == DECORATION_CALLABLE_NO_ARGS:
                data()

            elif dtype == DECORATION_TEXTURE_POLYGON:
                pos, texture, tx, ty, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)
                if isinstance(texture, pygame_menu.BaseImage):
                    texture = texture.get_surface()
                gfxdraw.textured_polygon(surface, pos, texture, tx, ty)

            elif dtype == DECORATION_ARC:
                points, r, ia, fa, color, width, gfx, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                x, y = points[0]
                rectarc = pygame.Rect(x - r, y - r, x + 2 * r, y + 2 * r)
                if gfx:
                    gfxdraw.arc(surface, x, y, r, ia, fa, color)
                else:
                    pydraw.arc(surface, color, rectarc, ia / (2 * pi), fa / (2 * pi), width)

            elif dtype == DECORATION_PIE:
                points, r, ia, fa, color, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                x, y = points[0]
                gfxdraw.pie(surface, x, y, r, ia, fa, color)

            elif dtype == DECORATION_BEZIER:
                points, color, steps, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                gfxdraw.bezier(surface, points, steps, color)

            elif dtype == DECORATION_RECT:
                drect: 'pygame.Rect'
                pos, drect, color, width, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0]
                drect = drect.copy()
                drect.x += pos[0]
                drect.y += pos[1]
                pygame.draw.rect(surface, color, drect, width)

            elif dtype == DECORATION_PIXEL:
                pos, color, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0]
                gfxdraw.pixel(surface, pos[0], pos[1], color)

            elif dtype == DECORATION_LINE:
                pos, color, width, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)
                pydraw.line(surface, color, pos[0], pos[1], width)

            else:
                raise ValueError('unknown decoration type')