From 74fb7c664c007e331cb4d8e5cfcc2d1e3040fe19 Mon Sep 17 00:00:00 2001 From: mxg3q47v5 <2167579360@qq.com> Date: Fri, 31 May 2024 10:46:07 +0800 Subject: [PATCH] ADD file via upload --- utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 utils.py diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..f78eba2 --- /dev/null +++ b/utils.py @@ -0,0 +1,19 @@ +import pygame + + +def scale_image(img, factor): + size = round(img.get_width() * factor), round(img.get_height() * factor) + return pygame.transform.scale(img, size) + + +def blit_rotate_center(win, image, top_left, angle): + rotated_image = pygame.transform.rotate(image, angle) + new_rect = rotated_image.get_rect( + center=image.get_rect(topleft=top_left).center) + win.blit(rotated_image, new_rect.topleft) + + +def blit_text_center(win, font, text): + render = font.render(text, 1, (200, 200, 200)) + win.blit(render, (win.get_width()/2 - render.get_width() / + 2, win.get_height()/2 - render.get_height()/2))