def _draw_circle(renderer, cx, cy, rad, color, sides=0):

    c = sdl2.ext.Color(*color)
    r, g, b, a = c.r, c.g, c.g, c.a

    _2pi = pi * 2

    if (sides == 0):
        sides = int(_2pi * rad / 2)

    d_a = _2pi / sides
    angle = d_a

    end_x = rad + cx
    end_y = 0.0 + cy
    i = 0
    sdl2.SDL_SetRenderDrawColor(renderer, r, g, b, a)
    while i != sides:
        start_x = end_x
        start_y = end_y
        end_x = cos(angle) * rad
        end_y = sin(angle) * rad
        end_x += cx
        end_y += cy
        angle += d_a

        sdl2.SDL_RenderDrawLine(renderer,
                                int(start_x), int(start_y),
                                int(end_x), int(end_y))
        i += 1
Esempio n. 2
0
 def drawLine(self, x1, y1, x2, y2):
     ''' Рисует линию по 2 точкам
      * @param  {number} x1 - X 1 точки
      * @param  {number} y1 - Y 1 точки
      * @param  {number} x2 - X 2 точки
      * @param  {number} y2 - Y 2 точки
      * @returns {self}
     '''
     SDL.SDL_RenderDrawLine(self.ctx, int(x1), int(y1), int(x2), int(y2))
     return self
Esempio n. 3
0
def draw_lines(renderer):

    global current_alpha, current_color, cycle_direction

    rect = sdl2.SDL_Rect()
    viewport = sdl2.SDL_Rect()

    sdl2.SDL_RenderGetViewport(renderer, ctypes.byref(viewport))

    for i in range(0, NUM_OBJECTS):
        current_color = current_color + cycle_direction
        if current_color < 0:
            current_color = 0
            cycle_direction = -cycle_direction
        if current_color > 255:
            current_color = 255
            cycle_direction = -cycle_direction

        sdl2.SDL_SetRenderDrawColor(renderer, 255, current_color,
                                    current_color, current_alpha)

        if i == 0:
            sdl2.SDL_RenderDrawLine(renderer, 0, 0, viewport.w - 1,
                                    viewport.h - 1)
            sdl2.SDL_RenderDrawLine(renderer, 0, viewport.h - 1,
                                    viewport.w - 1, 0)
            sdl2.SDL_RenderDrawLine(renderer, 0, int(viewport.h / 2),
                                    viewport.w - 1, int(viewport.h / 2))
            sdl2.SDL_RenderDrawLine(renderer, int(viewport.w / 2), 0,
                                    int(viewport.w / 2), viewport.h - 1)
        else:
            x1 = (int(random.random() * 65535) % (viewport.w * 2)) - viewport.w
            x2 = (int(random.random() * 65535) % (viewport.w * 2)) - viewport.w
            y1 = (int(random.random() * 65535) % (viewport.h * 2)) - viewport.h
            y2 = (int(random.random() * 65535) % (viewport.h * 2)) - viewport.h
            sdl2.SDL_RenderDrawLine(renderer, x1, y1, x2, y2)
Esempio n. 4
0
def oscillo_render(screen,
                   scrno,
                   data,
                   colours=[(255, 0, 0, 255), (0, 0, 255, 255)]):
    width, height = screen.dimensions
    sect_width = width / (len(data[0]) - 1)
    for i, channel in enumerate(data):
        screen.setcolour(colours[i])
        prev = None
        for j, datum in enumerate(channel):
            point = (int(sect_width * (j - 1)),
                     height // 2 + (-1)**i * datum * height // 2 // SCALE_DOWN)
            if prev is not None:
                sdl2.SDL_RenderDrawLine(screen.sdlrenderer, prev[0], prev[1],
                                        point[0], point[1])
            prev = point
Esempio n. 5
0
def updown_render(screen,
                  scrno,
                  data,
                  colours=[(96, 210, 255, 255), (200, 200, 200, 255),
                           (200, 000, 000, 255)]):
    width, height = screen.dimensions
    sect_width = width / len(data[0]) * scrno
    bars_each = int(len(data[0]) / scrno)
    screen.setcolour(colours[0])
    for i, channel in enumerate(data):
        for j, datum in enumerate(channel[screen.n * bars_each:(screen.n + 1) *
                                          bars_each]):
            screen.setcolour(
                colours[j % 2 if sect_width > RECOMMENDED_WIDTH else 0])
            bar = sdl2.SDL_Rect(
                int(j * sect_width), height // 2,
                int(sect_width) + 1,
                int((-1)**i * datum * height // 2 // SCALE_DOWN))
            sdl2.SDL_RenderFillRect(screen.sdlrenderer, bar)
    screen.setcolour(colours[2])
    sdl2.SDL_RenderDrawLine(screen.sdlrenderer, 0, height // 2, width,
                            height // 2)
Esempio n. 6
0
 def render(self, render_context):
     sdl2.SDL_RenderDrawLine(render_context.sdl_renderer, int(self.x),
                             int(self.y), int(self.x + self.sx),
                             int(self.y + self.sy))