pygame rotozoom code example

Example 1: rotation image pygame

import pygame as pg # Hey hey ! I hope this code will help you ! :)
# It is not the perfect method to rotate but it is easy to understand and efficient
pg.init()
Win = pg.display.set_mode((400, 400)) # You can choose width and height but wisely !

image = pg.image.load("""Choose an image among your files !!!""")

angle = 0
y0 = x0 = 100 # Choose the location of the image on screen
w, h = image.get_size()
Working = True #Mainloop initialization
while Working :
    pg.time.delay(50)
    for event in pg.event.get() :
        if event.type == pg.QUIT :
            En_marche = False

    Win.fill((0,0,0))
    rotated_image = pg.transform.rotate(image, angle) # Rotate...
    w1, h1 = (rotated_image.get_rect()[2], rotated_image.get_rect()[3]) # An intresting part
    x1 = x0 - w1 + w # New location to remove translation of the image
    y1 = x0 - h1 + h # Try to understand how it works ;)
    Win.blit(rotated_image, (x1/2, y1/2)) # A still image
    pg.display.update() # update...
    angle += 1 # Optional, your image will rotate more each turn

Example 2: rotation image pygame

import pygame as pg # Hey hey ! I hope this code will help you ! :)
# It is not the perfect method to rotate but it is easy to understand and efficient
pg.init()
Win = pg.display.set_mode((400, 400)) # You can choose width and height but wisely !

image = pg.image.load("""Choose an image among your files !!!""")

angle = 0
y0 = x0 = 100 # Choose the location of the image on screen
w, h = image.get_size()
Working = True #Mainloop initialization
while Working :
    pg.time.delay(50)
    for event in pg.event.get() :
        if event.type == pg.QUIT :
            Working = False

    Win.fill((0,0,0))
    rotated_image = pg.transform.rotate(image, angle) # Rotate...
    w1, h1 = (rotated_image.get_rect()[2], rotated_image.get_rect()[3]) # An intresting part
    x1 = x0 - w1 + w # New location to remove translation of the image
    y1 = x0 - h1 + h # Try to understand how it works ;)
    Win.blit(rotated_image, (x1/2, y1/2)) # A still image
    pg.display.update() # update...
    angle += 1 # Optional, your image will rotate more each turn