pygame rotozoom code example
Example 1: rotation image pygame
import pygame as pg
pg.init()
Win = pg.display.set_mode((400, 400))
image = pg.image.load("""Choose an image among your files !!!""")
angle = 0
y0 = x0 = 100
w, h = image.get_size()
Working = True
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)
w1, h1 = (rotated_image.get_rect()[2], rotated_image.get_rect()[3])
x1 = x0 - w1 + w
y1 = x0 - h1 + h
Win.blit(rotated_image, (x1/2, y1/2))
pg.display.update()
angle += 1
Example 2: rotation image pygame
import pygame as pg
pg.init()
Win = pg.display.set_mode((400, 400))
image = pg.image.load("""Choose an image among your files !!!""")
angle = 0
y0 = x0 = 100
w, h = image.get_size()
Working = True
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)
w1, h1 = (rotated_image.get_rect()[2], rotated_image.get_rect()[3])
x1 = x0 - w1 + w
y1 = x0 - h1 + h
Win.blit(rotated_image, (x1/2, y1/2))
pg.display.update()
angle += 1