HSV to RGB Color Conversion

That function expects decimal for s (saturation) and v (value), not percent. Divide by 100. >>> import colorsys # Using percent, incorrect >>> test_color = colorsys.hsv_to_rgb(359,100,100) >>> test_color (100, -9900.0, -9900.0) # Using decimal, correct >>> test_color = colorsys.hsv_to_rgb(1,1,1) >>> test_color (1, 0.0, 0.0) If you would like the non-normalized RGB tuple, here is a … Read more

Difference between pygame.display.update and pygame.display.flip

The main difference between pygame.display.flip and pygame.display.update is, that display.flip() will update the contents of the entire display display.update() allows to update a portion of the screen, instead of the entire area of the screen. Passing no arguments, updates the entire display To tell PyGame which portions of the screen it should update (i.e. draw … Read more

How to scale images to screen size in Pygame

You can scale the image with pygame.transform.scale: import pygame picture = pygame.image.load(filename) picture = pygame.transform.scale(picture, (1280, 720)) You can then get the bounding rectangle of picture with rect = picture.get_rect() and move the picture with rect = rect.move((x, y)) screen.blit(picture, rect) where screen was set with something like screen = pygame.display.set_mode((1600, 900)) To allow your … Read more

How to suppress console output in Python?

Just for completeness, here’s a nice solution from Dave Smith’s blog: from contextlib import contextmanager import sys, os @contextmanager def suppress_stdout(): with open(os.devnull, “w”) as devnull: old_stdout = sys.stdout sys.stdout = devnull try: yield finally: sys.stdout = old_stdout With this, you can use context management wherever you want to suppress output: print(“Now you see it”) … Read more