def __init__(self, fps=60): self.fps = fps self.screen = display.set_mode((0, 0), pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF) self.width = display.Info().current_w self.height = display.Info().current_h self.on = True
def check_user_monitor(x, y): if display.Info().current_w - 70 < x or display.Info().current_h - 60 < y: print( "Your monitor has too small resolution! We can't provide a good interface for it :(" ) SYSEXIT() else: return (x, y)
class game_borders(): DISPLAY_INFO = display.Info() SCREEN_SIZE = (DISPLAY_INFO.current_w, DISPLAY_INFO.current_h) BORDERS = [ Rect( 0, # left 0, 1, SCREEN_SIZE[1]), Rect( 0, # top 0, SCREEN_SIZE[0], 1), Rect( SCREEN_SIZE[0] - 1, # right 0, 1, SCREEN_SIZE[1]), Rect( 0, # bottom SCREEN_SIZE[1] - 1, SCREEN_SIZE[0], 1) ]
def __init__(self, parse, name=""): init() display.init() self.DIMS = (display.Info().current_w, display.Info().current_h) self.BG = Surface(self.DIMS) self.SCREEN = display.set_mode(self.DIMS, -2147483648) self.MANAGER = UIManager(self.DIMS) set_visible(True) update() Exit((0, 0), self.MANAGER) clear = Clear((0, 30), self.MANAGER) Spawn((0, 60), self.MANAGER, clear, self.DIMS, parse, name) Killer((0, 90), self.MANAGER, clear) Paint((0, 120), self.MANAGER) self.clock = Clock() while True: self.process_events()
def _init_image_viewer(self): if self._image_viewer == 'fbi': return self._display_with_fbi # else # Init pygame display display.init() # Hide mouse - unnecessary, since it's already # done by looper (?) # pygame.mouse.set_visible(False) # Prepare screen size = (display.Info().current_w, display.Info().current_h) self._screen = display.set_mode(size, FULLSCREEN) self.screenW, self.screenH = self._screen.get_size() # set screen to black self._blank_screen() logging.debug('Init configs') logging.debug(display.Info()) return self._display_with_pygame
def main(): Bubbles = [] infoObject = display.Info() screen = display.set_mode((infoObject.current_w, infoObject.current_h)) keypressed = True while keypressed: screen.fill([0, 0, 0]) CreateBubbles(Bubbles) DrawBubbles(Bubbles) time.wait(15) display.flip() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: keypressed = False
def __init__(self, x, y, cs: int, draw=True, surface=None): self.x = x self.y = y display_info = display.Info() self.screen_ratio_x = display_info.current_w / 512 self.screen_ratio_y = display_info.current_h / 384 if draw: pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load( "./assets/circle.png").convert_alpha() self.size = (int(round(2.25 * (109 - (9 * cs)))), int(round(2.25 * (109 - (9 * cs))))) self.image = pygame.transform.scale(self.image, self.size) self.Draw(surface)
def init_display(): ''' Initialize pygame display ''' # Get the size of the display display.init() # Hide the mouse pygame.mouse.set_visible(0) info = display.Info() max_y = info.current_h max_x = info.current_w _get_logger().info(info) # pylint: disable=no-member display.set_mode((max_x, max_y), pygame.NOFRAME)
def __init__(self, lights=False): pygame.init() di = display.Info() self.desksize = (di.current_w, di.current_h) surfaces = ('floor', 'wall', 'playerfloor', 'target', 'blocktarget', 'wallquarter', 'cornerquarter', 'jutquarter', 'emptyquarter', 'playertarget', 'blockfloor') sdict = dict((s + 'surface', pygame.image.load('surfaces/%s.png' % s)) for s in surfaces) self.__dict__.update(sdict) self.qs = { '000': (self.jutquartersurface, 0), '001': (self.wallquartersurface, 90), '010': (self.jutquartersurface, 0), '100': (self.wallquartersurface, 0), '011': (self.wallquartersurface, 90), '101': (self.cornerquartersurface, 0), '110': (self.wallquartersurface, 0), '111': (self.emptyquartersurface, 0) } self.qfs = (((-1, 0), (-1, -1), (0, -1), 0, (0, 0)), ((0, -1), (1, -1), (1, 0), 3, (0.5, 0)), ((1, 0), (1, 1), (0, 1), 2, (0.5, 0.5)), ((0, 1), (-1, 1), (-1, 0), 1, (0, 0.5))) self.sets([48, 48]) self.tilex = 48 self.tiley = 48 self.renderx = 0 self.rendery = 0 self.rs = [0, 0] self.scalefactor = 1 self.initdelay = 0.2 self.delay = 0.05 self.levelnamerect = None self.controlrects = [] self.lastmoves = -1 self.lastsecs = -1 self.mstart = None
def splash(size, name, path="splash.png"): environ['SDL_VIDEO_WINDOW_POS'] = "center" display.set_caption(name) wininfo = display.Info() screensize = (wininfo.current_w, wininfo.current_h) desktop = ImageGrab.grab() screen = display.set_mode(size, NOFRAME, 32) background = image.load(path).convert_alpha() w, h = size w //= 2 h //= 2 desktop = desktop.crop((screensize[0] // 2 - w, screensize[1] // 2 - h, screensize[0] // 2 + w, screensize[1] // 2 + h)) string = desktop.tostring() desktop = image.fromstring(string, size, desktop.mode) desktop.blit(background, (0, 0)) screen.blit(desktop, (0, 0)) display.update()
def __init__(self): self.__display_info = display.Info() # get current display information
def main(): ''' Run the slideshow ''' args = handle_arguments() if args.debug: args.log_level = 'INFO' # 5 seconds is too fast once images are cached: one cannot interupt easily args.show_time = 10 * 1000 # Configure logging logging.basicConfig( format='%(levelname)s:%(module)s.%(funcName)s:%(message)s', level=getattr(logging, args.log_level.upper())) # pylint: disable=no-member pygame.init() # init the pygame dislay (Sloooooow) init_display() info = display.Info() slide_show = Slideshow(gallery_id=args.gallery_id, gallery_url=args.gallery_url, downscale=args.downscale_only, height=info.current_h, width=info.current_w) # init fonts fonts = init_fonts() # Load main display area main_surface = pygame.display.get_surface() main_surface.fill(pygame.Color('black')) center_x = main_surface.get_rect().centerx center_y = main_surface.get_rect().centery # Display startup message for 5 seconds draw_multiline_text(surface=main_surface, text=STARTUP_TEXT, pos=(center_x, center_y), font=fonts['medium']) display.flip() pygame.time.delay(5000) # Start by drawing the first image update = draw_image(image_file=BytesIO(slide_show.current())) # update = draw_image(image_file=slide_show.current()) if update: display.flip() # draw an image at set intervals by sending an event on an interval # pylint: disable=no-member time.set_timer(pygame.USEREVENT, args.show_time) # the event loop while 1: update = True try: # pylint: disable=no-member for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) # keypresses if event.type == pygame.KEYUP: # look for escape key if event.key == pygame.K_ESCAPE: sys.exit(0) # left arrow - display the previous image if event.key == pygame.K_LEFT: # Draw the image update = draw_image( image_file=BytesIO(slide_show.previous())) # right arrow - display the next image if event.key == pygame.K_RIGHT: # Draw the image update = draw_image( image_file=BytesIO(slide_show.next())) # image display events if event.type == pygame.USEREVENT: # Draw the image update = draw_image(image_file=BytesIO(slide_show.next())) # Update the display - sometimes can't find a good image size match if update: display.flip() except KeyboardInterrupt: sys.exit(0)
TERRAIN_SIDE = request_size(9, 64) # Generate display size : PLOT_SIZE per plot # PLOT_PADDING between them # TERRAIN_MARGIN on each side SCREEN_SIZE = ( (PLOT_SIZE * TERRAIN_SIDE) + PLOT_PADDING * (TERRAIN_SIDE - 2) ) TERRAIN_MARGIN = int(1 / 10 * SCREEN_SIZE) TERRAIN_MARGIN = 40 if TERRAIN_MARGIN > 40 else TERRAIN_MARGIN # Add a margin to the screen SCREEN_SIZE += 2 * TERRAIN_MARGIN # Get display height display.init() DISPLAY_HEIGHT = display.Info().current_h # Check and warn user if SCREEN_SIZE # is taller than display if SCREEN_SIZE > DISPLAY_HEIGHT: print( "Warning: game terrain taller than " "screen height. The entire board will " "not fit. Modify values in const.py " "to resize." )
with open("settings.json", "w") as f: json.dump(data, f) exit() def Remove_profile(profile): with open("settings.json", "r") as f: data = json.load(f) del data[str(base64.b64encode(profile.encode("ascii")))[2:-1]] with open("settings.json", "w") as f: json.dump(data, f) exit() pygame.init() display_info = display.Info() width = display_info.current_w height = display_info.current_h resolution = [width, height] args = sys.argv[1:] if "-profile" in args: if args[args.index("-profile") + 1] == "-help" or args[args.index("-profile") + 1] == "-h" or args[args.index("-profile") + 1] == "-?": display_profiles() if args[args.index("-profile") + 1] == "-new": Add_profile() if args[args.index("-profile") + 1] == "-remove" or args[args.index("-profile") + 1] == "-r":
drawline_straight(screen, in2, color, len2, frameheight) pygame.display.flip() #print( in1, in2) if __name__ == "__main__": os.environ['SDL_VIDEODRIVER'] = 'windib' pygame.init() pygame.display.set_caption('Sortingalgorithms') if pygame.display.get_init(): screen = pygame.display.set_mode((780, 460)) bckgr = (0, 0, 0) screen.fill(bckgr) height = getattr(display.Info(), 'current_h') width = getattr(display.Info(), 'current_w') lower_bound = 0 upper_bound = height length = width numbers_unsorted = generate_randomsequence(lower_bound, upper_bound, length) #numbers_unsorted = [i for i in range(100,200)] #numbers_unsorted += [i for i in range(0,100)] #print(numbers_unsorted) clr = (255, 255, 255) for ind, num in enumerate(numbers_unsorted): drawline_straight(screen, ind, clr, num, height) pygame.display.flip()
def resz(size): return max(int(float(size) * float(sz)), 1) def reszy(size): return max(int(float(size) * float(szy)), 1) #SCREEN_SIZE_MODE = "auto" SCREEN_SIZE_MODE = "1024_720" if SCREEN_SIZE_MODE == "auto": display.init() infoObject = display.Info() SIZE000 = (infoObject.current_w, infoObject.current_h) else: splitted = SCREEN_SIZE_MODE.split("_") SIZE000 = int(splitted[0]), int(splitted[1]) sz = float(SIZE000[0]) / 1440.0 szy = float(SIZE000[1]) / 855.0 sz = 1.3 szy = 1.3 print sz bs = int(45.0 * sz) SIZE = (int(1440.0 * sz), int(855.0 * szy))
def get_display_size(): mode_info = display.Info() return mode_info.current_w, mode_info.current_h
from pygame import sprite, image, transform, Rect, display inf = display.Info() x, y = inf.current_w / 30, inf.current_h / 17 if x > y: SIZE_OF_RECT = int(y) else: SIZE_OF_RECT = int(x) class Brick(sprite.Sprite): def __init__(self, cords, rect_size, image_name, can_be_broken, shift=(0, 0)): super().__init__() self.rect_size = rect_size self.cords = cords self.image = transform.scale(image.load(image_name).convert(), rect_size) self.image.set_colorkey((255, 255, 255)) self.rect = Rect(0, 0, *rect_size) self.image_name = image_name self.shift = shift self.can_be_broken = can_be_broken class SavePoint(sprite.Sprite): def __init__(self, cords, rect_size): super().__init__() self.cords = cords self.image = image.load('tiles\\save_point\\1.png').convert() self.image = transform.scale(self.image, rect_size) self.image.set_colorkey((255, 255, 255)) self.rect = Rect(0, 0, *rect_size)
from pygame.math import Vector2 from pygame import display FULLSCREEN = False if FULLSCREEN: display.init() screen = display.Info() WIDTH = int(screen.current_w) HEIGHT = int(screen.current_h) else: WIDTH = 800 HEIGHT = 600 MAXROCKETS = 500 GRAVITY = Vector2(0,0.01) LIFESPAN = 600 MUTATIONFACTOR = 1 TARGETPOS = (WIDTH/2,int(HEIGHT*0.1)) FONTSIZE = 14 RED = (255,0,0) WHITE = (255,255,255) MAXOBSTACLES = 20 OBSTACLETESTLIMIT = 30
def spawn(self): player_data = PlayerData( 4, 750, Vector2(display.Info().current_w / 2, display.Info().current_h / 2), 10) self._player = PlayerSprite(self._res_container, player_data)
import os import sys from pygame.constants import K_RIGHT def resource_path(relative_path): try: base_path = sys._MEIPASS except Exception: base_path = os.path.abspath(".") return os.path.join(base_path, relative_path) init() sw, sh = display.Info().current_w, display.Info().current_h iconi = image.load(resource_path('falg.png')) display1 = display.set_mode((sw, sh), FULLSCREEN) white = [255, 255, 255] black = [0, 0, 0] mouse.set_visible(False) display.set_caption('CCCP -- USSR') display1.fill(white) mixer.music.load(resource_path('anthemstalin.wav')) player = image.load(resource_path('stalin.JPEG')) x = 0 y = 0 a = 1 b = 1 display.update() mixer.music.play(-1)