1

I was wondering how I can keep rotating a simple square in pygame.

I have written this simple code with a black background and a white square drawn in the middle. How could I keep rotating that white square?

Heres the program:

import pygame
pygame.init()

window = pygame.display.set_mode((500,500))
pygame.display.set_caption("code man")


# the square

class square:
    def __init__(self,x,y,height,width,color):
        self.x = x
        self.y = y
        self.height = height
        self.width = width
        self.color = color
        self.rect = pygame.Rect(x,y,height,width)
    def draw(self):
        self.rect.topleft = (self.x,self.y)
        pygame.draw.rect(window,self.color,self.rect)

white = (255,255,255)
square1 = square(200,200,50,50,white)


# redraw the window

def redraw():
    BLACK = (0,0,0)

    # fill the window black
    window.fill(BLACK)

    # draw the square
    square1.draw()

    # update the screen
    pygame.display.update()

# the main loop
runninggame = True
while runninggame:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            runninggame = False


    # call the redraw
    redraw()

    
   

Qiu YU
  • 517
  • 4
  • 20
Habib Ismail
  • 69
  • 5
  • 16
  • Rabbid76 did an excellent answer on plain rotation, which goes into some of the pitfalls with off-centre rotation, etc.: https://stackoverflow.com/a/54714144/1730895 – Kingsley Aug 12 '20 at 00:40

0 Answers0