how to get the angle of mouse from the center
# if you want to find the angle the mouse position is from the center
# heres the formula
angle = 360 - math.atan2(pos[1] - (half of screenheight), pos[0] - (half of screenwidth)) * 180 / math.pi
pygame rotate image
import pygame
import pygame.font

pygame.init()
size = (400,400)
screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()

def blitRotate(surf, image, pos, originPos, angle):

    # calcaulate the axis aligned bounding box of the rotated image
    w, h       = image.get_size()
    box        = [pygame.math.Vector2(p) for p in [(0, 0), (w, 0), (w, -h), (0, -h)]]
    box_rotate = [p.rotate(angle) for p in box]
    min_box    = (min(box_rotate, key=lambda p: p[0])[0], min(box_rotate, key=lambda p: p[1])[1])
    max_box    = (max(box_rotate, key=lambda p: p[0])[0], max(box_rotate, key=lambda p: p[1])[1])

    # calculate the translation of the pivot 
    pivot        = pygame.math.Vector2(originPos[0], -originPos[1])
    pivot_rotate = pivot.rotate(angle)
    pivot_move   = pivot_rotate - pivot

    # calculate the upper left origin of the rotated image
    origin = (pos[0] - originPos[0] + min_box[0] - pivot_move[0], pos[1] - originPos[1] - max_box[1] + pivot_move[1])

    # get a rotated image
    rotated_image = pygame.transform.rotate(image, angle)

    # rotate and blit the image
    surf.blit(rotated_image, origin)

    # draw rectangle around the image
    pygame.draw.rect (surf, (255, 0, 0), (*origin, *rotated_image.get_size()),2)

font = pygame.font.SysFont('Times New Roman', 50)
text = font.render('image', False, (255, 255, 0))
image = pygame.Surface((text.get_width()+1, text.get_height()+1))
pygame.draw.rect(image, (0, 0, 255), (1, 1, *text.get_size()))
image.blit(text, (1, 1))
w, h = image.get_size()

angle = 0
done = False
while not done:
    clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.KEYDOWN:
            if event.key==pygame.K_ESCAPE:
                done = True

    pos = (screen.get_width()//2, screen.get_height()//2)
    pos = (200, 200)

    screen.fill(0)
    blitRotate(screen, image, pos, (w//2, h//2), angle)
    angle += 1

    pygame.draw.line(screen, (0, 255, 0), (pos[0]-20, pos[1]), (pos[0]+20, pos[1]), 3)
    pygame.draw.line(screen, (0, 255, 0), (pos[0], pos[1]-20), (pos[0], pos[1]+20), 3)
    pygame.draw.circle(screen, (0, 255, 0), pos, 7, 0)

    pygame.display.flip()

pygame.quit()
how to rotate image in pygame
# first argument is the original_image
# second one is the angle by how much angle you want you image to be rotated
# third is the zoom amount here it is set to 1 because we don't need to zomm in or out

img_rotated = pygame.transform.rotozoom(original_image,angle,1)

# NOTE: you can use the pygame.transform.rotate but some times rotozoom works better
#** -*=\ Happy Coding /=*- **#

Ninja Hatori Cat Codr (https://github.com/PrathameshBhatkar)
                      (https://www.youtube.com/channel/UCHzOI93T5ZZ4TqYJqz6WmYQ)
rotate image in pygame
# Import pygame
import pygame
  
# Initialise pygame
pygame.init()
  
# Set window size
size = width,height = 600, 600
screen = pygame.display.set_mode(size)
  
# Clock
clock = pygame.time.Clock()
  
# Load image
image = pygame.image.load('gfg.png')
  
# Set the size for the image
DEFAULT_IMAGE_SIZE = (200, 200)
  
# Rotate the image by any degree
image = pygame.transform.rotate(image, 180)
  
# Set a default position
DEFAULT_IMAGE_POSITION = (200,200)
  
# Prepare loop condition
running = False
  
# Event loop
while not running:
  
    # Close window event
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = True
  
    # Background Color
    screen.fill((0, 0, 0))
  
    # Show the image
    screen.blit(image, DEFAULT_IMAGE_POSITION)
  
    # Part of event loop
    pygame.display.flip()
    clock.tick(30)

Python相关代码片段

python parquet file to csv

python best practices

yolov5 without net

save variable as pkl python

python [-9:]

eigenface python

'DataFrame' object has no attribute 'dtype'

unable to enable maximize window tkinter

rabbit and fox numpy python

lstm in keras

neural network in keras

resnet50 in keras

autoencoder in keras

cnn in keras

tensor in keras

pyTelegramBotAPI edit photo

print api python

how to get values but not index from pandas series

how to get mode of a column from pandas

bayesian neural network pymcmc

lda python

back propagation python

logical syntax is not none python

register model django

Descending Selection sort

Selection sort with while loops

Selection sort with for loops

Doubling Algorithm for cluster analysis in python

Tkinter widgets

nameerror: name 'callable' is not defined

NameError: name 'Union' is not defined

Make a widget customtkinter python

nn module pytorch

import tf python

Spark SEssion object

Implement Bubble sort with while loops

Unoptimized bubble sort algorithm

Optimized bubble sort algorithm

how to get today's date in python

st_aggrid install

python venv pip blocked by admin windows

numpy matrix from lists of different leght

python postgres auto commit

dotenv install python

np mean axis

LinkExtractor Object

admin django documentation

Python native Convolution implementation

is django monolithic

what is function call with an llm

np array to series

dht22 micropython pico

disable slash command discord.py

python docker compose not printing

tabnet probabilities

python venv: no such file or directory

find most common words in string python

histogram equalization using pillow

Django squash migrations

swap first and last letter in string in array

sor a lit in python

torch clear cuda cache

multi line comment python

password login and logout in python

string to array iin python

no organize imports action available

different clustering algorithms

python colur text

anki addons how to use external libraries

Python Modbus TCP

install python3 latest version with conda

semantics python

python find mode of a list

add more inputs to the user model in django

pycharm pdm __pypackages__

splitlines in python

flask opencv streamer

pytorch create dataset from tensor

statics in django

python anywhere selenium