def _set_color(self, is_on): if is_on: sdl2.SDL_SetRenderDrawColor(self.renderer, 0x10, 0x10, 0x10, sdl2.SDL_ALPHA_OPAQUE) else: sdl2.SDL_SetRenderDrawColor(self.renderer, 0xe8, 0xe8, 0xee, sdl2.SDL_ALPHA_OPAQUE)
def render_background(self, renderer, screen_width, screen_height): sdl2.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255) sdl2.SDL_RenderCopy( renderer, self.texture, None, sdl2.SDL_Rect(int(screen_width - self.size), int(screen_height - self.size), int(self.size), int(self.size)))
def run(): boxes = [Box(sdl2.SDL_Rect(0, int(1080 * 0.8 / 2) - 50, 100, 100))] last_tick = sdl2.SDL_GetTicks() while App.running: for box in boxes: box.update() for window in App.windows: renderer = window["renderer"] sdl2.SDL_SetRenderDrawColor(renderer, 30, 30, 30, 255) sdl2.SDL_RenderClear(renderer) for box in boxes: box.render() for window in App.windows: renderer = window["renderer"] sdl2.SDL_RenderPresent(renderer) Events.handle_events() current_tick = sdl2.SDL_GetTicks() last_tick = last_tick + App.FRAME_DURATION delay = last_tick - current_tick sdl2.SDL_Delay(int(max(0, delay)))
def draw_rects(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) rect.w = (int(random.random() * 65535) % int(viewport.h / 2)) rect.h = (int(random.random() * 65535) % int(viewport.h / 2)) rect.x = ((int(random.random() * 65535) % (viewport.w * 2)) - viewport.w) - int(rect.w / 2) rect.y = ((int(random.random() * 65535) % (viewport.h * 2)) - viewport.h) - int(rect.h / 2) sdl2.SDL_RenderFillRect(renderer, ctypes.byref(rect))
def draw(self, renderer, text, rect, color, selected=None, kerning=True, wrap=True, lines=None): """ Renders text in the specified rect, using the specified color. If specified, selected is a set of indexes in text that should be highlighted. """ y = rect.top if lines is None: lines = list( self.layout(text, rect.width, kerning=kerning, wrap=wrap)) for line in lines: for idx, code, x, kern, extent in line: tex, size = self.glyph(renderer, code) sdl2.SDL_SetTextureColorMod(tex, color.r, color.g, color.b) sdl2.SDL_SetTextureAlphaMod(tex, color.a) dst = sdl2.SDL_Rect(rect.left + x + kern, y, size.w, size.h) sdl2.SDL_RenderCopy(renderer, tex, None, ctypes.byref(dst)) if selected and idx in selected: sdl2.SDL_SetRenderDrawColor(renderer, 20, 60, 120, 255) sdl2.SDL_SetRenderDrawBlendMode(renderer, sdl2.SDL_BLENDMODE_ADD) sdl2.SDL_RenderFillRect( renderer, sdl2.SDL_Rect(rect.left + x, y, size.w + kern, size.h)) y += self.line_height return lines
def run(self) -> None: e = sdl2.SDL_Event() while not self.context.quit: while sdl2.SDL_PollEvent(ctypes.byref(e)) != 0: if e.type == sdl2.SDL_QUIT: self.context.quit = True self.world.handle_event(e) self.world.handle_keyboard(sdl2.SDL_GetKeyboardState(None)) self.world.clean() self.world.process_physics() self.world.detect_collisions() self.world.animate() sdl2.SDL_SetRenderDrawColor(self.context.renderer, 0xff, 0xff, 0xff, 0xff) sdl2.SDL_RenderClear(self.context.renderer) self.world.render(self.world.frame.center, self.world.camera.global_position(), self.world.camera.frame.size) self.ui.render(self.ui.frame.center, Vector2D(), self.world.camera.originalSize) sdl2.SDL_RenderPresent(self.context.renderer) self.exit()
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
def draw_apple(game, renderer): global cell_size x = int(game.apple.x * cell_size + cell_size / 4) y = int(game.apple.y * cell_size + cell_size / 4) size = int(cell_size / 2) rect = sdl2.SDL_Rect(x, y, size, size) sdl2.SDL_SetRenderDrawColor(renderer, 255, 0, 0, 0) sdl2.SDL_RenderFillRect(renderer, rect)
def main(): sdl2.sdl2_load(ctypes.util.find_library('SDL2'), # '/usr/local/lib/libSDL2.dylib' ttf_libpath = ctypes.util.find_library('SDL2_ttf'), img_libpath = ctypes.util.find_library('SDL2_image') ) sdl2.SDL_Init(sdl2.SDL_INIT_EVERYTHING) WINDOW_W = 640 WINDOW_H = 360 window = sdl2.SDL_CreateWindow(b"Minimal SDL_Image Test via python-sdl2", 0, 0, WINDOW_W, WINDOW_H, sdl2.SDL_WINDOW_OPENGL) renderer = sdl2.SDL_CreateRenderer(window, -1, 0) sdl2.IMG_Init(sdl2.IMG_INIT_JPG|sdl2.IMG_INIT_PNG|sdl2.IMG_INIT_TIF|sdl2.IMG_INIT_WEBP) rwops_ptr = sdl2.SDL_RWFromFile(bytes(sys.argv[1], 'utf-8'), b"rb") print("PNG?: %s" % ('true' if sdl2.IMG_isPNG(rwops_ptr) else 'false')) texture = sdl2.IMG_LoadTexture_RW(renderer, rwops_ptr, 1) wh = 300 pos = sdl2.SDL_Rect() pos.x = int((WINDOW_W - wh) / 2) pos.y = int((WINDOW_H - wh) / 2) pos.w = wh pos.h = wh sdl2.SDL_RenderCopy(renderer, texture, None, ctypes.byref(pos)) sdl2.SDL_RenderPresent(renderer) fpsdelay = 100 count = 0 event = sdl2.SDL_Event() done = False while not done: while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0: # 'type' and 'timestamp' are common members for all SDL Event structs. event_type = event.common.type event_timestamp = event.common.timestamp # print("Event : type=0x%s, timestamp=%s" % (event_type, event_timestamp) ) if event_type == sdl2.SDL_KEYDOWN: if event.key.keysym.sym == sdl2.SDLK_ESCAPE: done = True sdl2.SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF) sdl2.SDL_RenderClear(renderer) sdl2.SDL_RenderCopy(renderer, texture, None, ctypes.byref(pos)) sdl2.SDL_RenderPresent(renderer) sdl2.SDL_Delay(fpsdelay) sdl2.IMG_Quit() sdl2.SDL_DestroyRenderer(renderer) sdl2.SDL_DestroyWindow(window) sdl2.SDL_Quit()
def render_frame(self, pixels): sdl2.SDL_SetRenderDrawColor(self.renderer, 0, 0, 0, sdl2.SDL_ALPHA_OPAQUE) sdl2.SDL_RenderClear(self.renderer) for x, y, colour in pixels: self.render_pixel(x, y, colour) # show current frame sdl2.SDL_RenderPresent(self.renderer)
def render_npcs(self, renderer, screen_width, screen_height, entities): sdl2.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255) for character in entities.characters: sdl2.SDL_RenderFillRect( renderer, sdl2.SDL_Rect(self.get_adjusted_x(character, screen_width), self.get_adjusted_y(character, screen_height), MiniMap.character_dot_size, MiniMap.character_dot_size))
def render_locations(self, renderer, screen_width, screen_height, entities): sdl2.SDL_SetRenderDrawColor(renderer, 80, 80, 80, 255) for location in entities.locations: sdl2.SDL_RenderFillRect( renderer, sdl2.SDL_Rect(self.get_adjusted_x(location, screen_width), self.get_adjusted_y(location, screen_height), int(location.width * self.x_scale), int(location.height * self.y_scale)))
def draw(self): if self.i < 127: self.i += 1 sdl2.SDL_SetRenderDrawColor(self.ren.sdlrenderer, 255, 255, 255, 255) width, height = self.font_manager.renderTextToSurfaceAndSave( f"Output/char_{self.i}.png", chr(self.i), self.font) else: exit(0)
def draw( self, waveform: list, colors: tuple # background and foreground colors ): # Compute a Fourier Transform on the Waveform to # divide the sound into several "bins". To # visualise them as points on the render window. self.fft_spectrum = fft_abs(fft(waveform))[:self.fft_bins] x = 0 # reset the coordinate on each call for idx, bin in enumerate(self.fft_spectrum): self.data_points.contents[idx] = sdl2.SDL_Point( round(x), int(maprange(bin, 0, NP_FFT_MAXVAL, 0, self.viewport['width']))) x += self.bar_width # Clear the canvas with our selected colour. # What it does is repaints the screen # the previous frame is overlapped by it. sdl2.SDL_SetRenderDrawColor(self.renderer, colors[0][0], colors[0][1], colors[0][2], colors[0][3]) sdl2.SDL_RenderClear(self.renderer) # Draw the visualization using connected paths which # are stroked. When percepted they represent themeselves # as "lines". sdl2.SDL_SetRenderDrawColor(self.renderer, colors[1][0], colors[1][1], colors[1][2], colors[1][3]) sdl2.SDL_RenderDrawLines(self.renderer, self.data_points.contents, self.fft_bins) # Display the contents on the screen which # was rendered off-screen. sdl2.SDL_RenderPresent(self.renderer) # Look for the event when the user closes # the render window. sdl2.SDL_PollEvent(self.event) if self.event.type == sdl2.SDL_QUIT: self.close() return True
def render_object_from_color(cls, renderer: sdl2.SDL_Renderer, color: Color) -> RenderObject: texture = sdl2.SDL_CreateTexture(renderer, sdl2.SDL_PIXELFORMAT_RGBA8888, sdl2.SDL_TEXTUREACCESS_TARGET, 1, 1) sdl2.SDL_SetRenderTarget(renderer, texture) sdl2.SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a) sdl2.SDL_RenderClear(renderer) sdl2.SDL_SetRenderTarget(renderer, None) return RenderObject(texture)
def fill(self, colour): self.type = "rect" if len(colour) == 3: colour = (colour[0] % 256, colour[1] % 256, colour[2] % 256, 255) elif len(colour) == 4: colour = (colour[0] % 256, colour[1] % 256, colour[2] % 256, colour[3] % 256) sdl2.SDL_SetRenderDrawColor(self.renderer, colour[0], colour[1], colour[2], colour[3]) sdl2.SDL_RenderClear(self.renderer)
def render_roads(self, renderer, screen_width, screen_height, entities): sdl2.SDL_SetRenderDrawColor(renderer, 48, 48, 48, 255) for road in entities.map_elements: if road.type != MapElementType.ROAD: continue sdl2.SDL_RenderFillRect( renderer, sdl2.SDL_Rect(self.get_adjusted_x(road, screen_width), self.get_adjusted_y(road, screen_height), int(road.width * self.x_scale), int(road.height * self.y_scale)))
def render_player(self, renderer, screen_width, screen_height, entities): sdl2.SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255) sdl2.SDL_RenderFillRect( renderer, sdl2.SDL_Rect( int( self.get_adjusted_x(entities.player, screen_width) - MiniMap.player_dot_size / 2), int( self.get_adjusted_y(entities.player, screen_height) - MiniMap.player_dot_size / 2), MiniMap.player_dot_size, MiniMap.player_dot_size))
def setColor(self, *color): ''' Задать текущий цвет * @param {array} color - Цвет в RGB формате * @returns {self} ''' if len(color) == 1: color = color[0] cl = Color(color) self.Draw['color'] = cl SDL.SDL_SetRenderDrawColor(self.ctx, *cl.getRgbaArray()) return self
def draw_snake(game, renderer): global cell_size sdl2.SDL_SetRenderDrawColor(renderer, 0, 255, 0, 0) dir_rects = get_dir_rects() body = deque(game.snake.body) for part in body: x = cell_size * part.x y = cell_size * part.y from_rect = make_custom_rect(x, y, dir_rects[part.from_dir]) to_rect = make_custom_rect(x, y, dir_rects[part.to_dir]) sdl2.SDL_RenderFillRect(renderer, from_rect) sdl2.SDL_RenderFillRect(renderer, to_rect)
def InitializeSDL(self): # SDL sub systems sdl2.SDL_Init(sdl2.SDL_INIT_EVERYTHING) # Video sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) # Window self.window = sdl2.SDL_CreateWindow("shoot 0.0.1",\ sdl2.SDL_WINDOWPOS_UNDEFINED,\ sdl2.SDL_WINDOWPOS_UNDEFINED, 640,\ 480,\ sdl2.SDL_WINDOW_SHOWN) # renderer self.sdl_renderer = sdl2.SDL_CreateRenderer(self.window, -1,\ sdl2.SDL_RENDERER_ACCELERATED) sdl2.SDL_SetRenderDrawColor(self.sdl_renderer, 255, 255, 255, 0) # Sound (from tutorial: http://lazyfoo.net/SDL_tutorials/lesson11/index.php ) # Initialize sdl mixer # Mix_OpenAudio args # First arg (22050) is sound frequency (recommended according to multiple tutorials, # but look into this) # Second arg is sound format # Third arg is number of channels we plan to use (e.g., 2 for stereo sound) # Fourth arg is the sample size (should be 4096) # Audio #sdl2.SDL_Init(sdl2.SDL_INIT_AUDIO) # If using SDL sound; shouldn't do this sdl2.sdlmixer.Mix_Init(sdl2.sdlmixer.MIX_INIT_MOD) # Insert the file formats you wish to allow here, e.g. OGG sdl2.sdlmixer.Mix_OpenAudio(22050, sdl2.sdlmixer.MIX_DEFAULT_FORMAT, 2, 4096) # TTF sdl2.sdlttf.TTF_Init() # Joystick sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK) self.joystick = sdl2.SDL_JoystickOpen(0) # Event self.input = sdl2.SDL_Event()
def _refresh(self): """ Draws the entire GUI when it needs to be updated """ # Clear with white sdl2.SDL_SetRenderDrawColor(self.renderer, 255, 255, 255, 255) sdl2.SDL_RenderClear(self.renderer) # TODO # For each element of the layout, call its draw method for el in self.layout_elements: el.draw(self.renderer) # Render to the screen sdl2.SDL_RenderPresent(self.renderer)
def draw(renderer, window_size): sdl2.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255) sdl2.SDL_RenderClear(renderer) a_base = min(window_size) a = A_COEFF_RELATION * a_base for part in PARTS: points_set = set() c_r, c_g, c_b, c_a = part[2] sdl2.SDL_SetRenderDrawColor(renderer, c_r, c_g, c_b, c_a) t = part[0] while t < part[1]: x = a * cos(t) * (1 + cos(t)) + window_size[0] / 2 - a y = a * sin(t) * (1 + cos(t)) + window_size[1] / 2 points_set.add((trunc(x), trunc(y))) t += STEP points_count = len(points_set) points_list = [sdl2.SDL_Point(p[0], p[1]) for p in points_set] points_array = (sdl2.SDL_Point * points_count)(*points_list) sdl2.SDL_RenderDrawPoints(renderer, points_array, points_count) sdl2.SDL_RenderPresent(renderer)
def prepare(): App.running = True App.num_displays = sdl2.SDL_GetNumVideoDisplays() logger.info(f"Number of displays: {App.num_displays}") for display in range(0, App.num_displays): rect = sdl2.SDL_Rect() sdl2.SDL_GetDisplayBounds(display, rect) border_width = rect.w * App.BORDER_WIDTH_PERCENT / 100 border_height = rect.h * App.BORDER_WIDTH_PERCENT / 100 window = sdl2.SDL_CreateWindow( f"{display}".encode("ascii"), 0, 0, int(rect.w - 2 * border_width), int(rect.h - 2 * border_height), int(sdl2.SDL_WINDOW_BORDERLESS), ) window_id = sdl2.SDL_GetWindowID(window) renderer = sdl2.SDL_CreateRenderer(window, -1, 0) sdl2.SDL_SetRenderDrawColor(renderer, 30, 30, 30, 255) sdl2.SDL_ShowWindow(window) sdl2.SDL_SetWindowPosition(window, int(rect.x + border_width), int(rect.y + border_height)) scale_factor = (100 - 2 * App.BORDER_WIDTH_PERCENT) / 100 internal_rect = sdl2.SDL_Rect( int(rect.x * scale_factor), int(rect.y * scale_factor), int(rect.w * scale_factor), int(rect.h * scale_factor), ) App.windows.append({ "rect": rect, "internal_rect": internal_rect, "window_id": window_id, "window": window, "renderer": renderer, }) Events.add_listener(*App.handle_window_leave) Events.add_listener(*App.handle_window_close) Events.add_listener(*App.handle_q)
def do_redraw(self): if self.renderer is None: return import sdl2 as sdl c = Color((100, 100, 100)) if self.style != None: c = Color(self.style.get("topbar_bg")) sdl.SDL_SetRenderDrawColor(self.renderer, 0, 0, 0, 0) sdl.SDL_RenderClear(self.renderer) # Draw topbar background: topbar_actual_height = max( round(self.padding_vertical * self.dpi_scale) * 2, self.topbar_height) draw_rectangle(self.renderer, 0, 0, self._width, topbar_actual_height, color=c) # Draw topbar items: self.topbar_box.draw( self.topbar_box.x, self.topbar_box.y) # Draw border: c = Color((100, 100, 100)) if self.style != None: c = Color(self.style.get("border")) if self.style.has("topbar_border"): c = Color(self.style.get("topbar_border")) draw_rectangle(self.renderer, 0, topbar_actual_height, self._width, self.border_size, color=c) # Draw background of below-topbar area: c = Color((255, 255, 255)) if self.style != None: c = Color(self.style.get("window_bg")) draw_rectangle(self.renderer, 0, self.topbar_height + self.border_size, self._width, self._height - topbar_actual_height - self.border_size, color=c) # Draw below-topbar items: for child in self._children: child.draw(child.x, child.y)
def render(self, force=False): if not self.needs_render and not force: return # Set this up front, so that the act of rendering can request another render. self.needs_render = False sdl2.SDL_SetRenderDrawColor(self.renderer, *self.background, sdl2.SDL_ALPHA_OPAQUE) sdl2.SDL_RenderClear(self.renderer) self.view.render(self.renderer) focus_view = self.view.resolve(self.focus) if focus_view and focus_view.draws_focus: focus_rect = focus_view.frame + Insets(focus_view.env.scaled(1)) self.view.env.draw(self.renderer, "focus", focus_rect) if self.menu: self.menu.render(self.renderer) sdl2.SDL_RenderPresent(self.renderer)
def render_pixel(self, x, y, colour): # can't use the below as too slow big_x = 5 * x big_y = 5 * y sdl2.SDL_SetRenderDrawColor(self.renderer, *colour, sdl2.SDL_ALPHA_OPAQUE) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 1, big_y) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 2, big_y) sdl2.SDL_RenderDrawPoint(self.renderer, big_x, big_y + 1) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 1, big_y + 1) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 2, big_y + 1) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 3, big_y + 1) sdl2.SDL_RenderDrawPoint(self.renderer, big_x, big_y + 2) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 1, big_y + 2) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 2, big_y + 2) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 3, big_y + 2) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 1, big_y + 3) sdl2.SDL_RenderDrawPoint(self.renderer, big_x + 2, big_y + 3)
def main(): sdl2.sdl2_load( ctypes.util.find_library('SDL2')) # '/usr/local/lib/libSDL2.dylib' sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) WINDOW_W = 640 WINDOW_H = 360 window = sdl2.SDL_CreateWindow( b"RenderDrawPoint/RenderDrawLine/RenderFillRect", 0, 0, WINDOW_W, WINDOW_H, sdl2.SDL_WINDOW_OPENGL) renderer = sdl2.SDL_CreateRenderer(window, -1, 0) event = sdl2.SDL_Event() done = False while not done: while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0: # 'type' and 'timestamp' are common members for all SDL Event structs. event_type = event.common.type event_timestamp = event.common.timestamp print("Event : type=0x%s, timestamp=%s" % (event_type, event_timestamp)) if event_type == sdl2.SDL_KEYDOWN: if event.key.keysym.sym == sdl2.SDLK_ESCAPE: done = True sdl2.SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF) sdl2.SDL_RenderClear(renderer) draw_points(renderer) draw_lines(renderer) draw_rects(renderer) sdl2.SDL_RenderPresent(renderer) sdl2.SDL_Quit()
def draw_points(renderer): global current_alpha, current_color, cycle_direction viewport = sdl2.SDL_Rect() sdl2.SDL_RenderGetViewport(renderer, ctypes.byref(viewport)) for i in range(0, 10 * 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) x = int(random.random() * 65535) % viewport.w y = int(random.random() * 65535) % viewport.h sdl2.SDL_RenderDrawPoint(renderer, x, y)
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)