Cope 2.5.0
My personal "standard library" of all the generally useful code I've written for various projects over the years
Loading...
Searching...
No Matches
pygame.py
1"""
2Functions & classes that extend the pygame library
3"""
4__version__ = '0.0.0'
5
6# from .imports import lazy_import
7# from .misc import RedirectStd
8# from typing import Union
9try:
10 # Don't print the annoying "welcome from the pygame community!" message
11 with RedirectStd():
12 import pygame
13except: pass
14else:
15 # TODO: tests
16 def rotateSurface(surface:pygame.Surface, angle:float, pivot:tuple|list|pygame.math.Vector2, offset:pygame.math.Vector2):
17 # def rotateSurface(surface, angle:float, pivot:tuple|list|"pygame.math.Vector2", offset:"pygame.math.Vector2"):
18 """ Rotate the surface around the pivot point.
19
20 Args:
21 surface (pygame.Surface): The surface that is to be rotated.
22 angle (float): Rotate by this angle.
23 pivot (tuple, list, pygame.math.Vector2): The pivot point.
24 offset (pygame.math.Vector2): This vector is added to the pivot.
25 """
26
27 rotated_image = pygame.transform.rotozoom(surface, -angle, 1) # Rotate the image.
28 rotated_offset = offset.rotate(angle) # Rotate the offset vector.
29 # Add the offset vector to the center/pivot point to shift the rect.
30 rect = rotated_image.get_rect(center=pivot+rotated_offset)
31 return rotated_image, rect # Return the rotated image and shifted rect.