Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rotating a rectangle
#1
Hello, i'm having trouble rotating a rectangle on screen. I'm not a computer science student and I need help because I have been at it for a couple of days.

The goal is to rotate a rectangle around it's top left corner like a sail around a post, but now the white rectangle rotates around it's center in a black square...

Here's my code:

import random, pygame, sys
from pygame.locals import *

Blue = (0,0,255)
Green = (0,255,0)
White = (255,255,255)

pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
DISPLAYSURF.fill(Blue)
pygame.display.set_caption('Sailing!')

FPS = 30
fpsClock = pygame.time.Clock()

Sail = pygame.Surface([100,10])
Sail.fill(White)

degrees = 0

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    rotatedSail = pygame.transform.rotozoom(Sail, degrees, 1)
    Sail_rect = Sail.get_rect(topleft =(200,150))
    DISPLAYSURF.blit(rotatedSail, Sail_rect)
    pygame.display.flip()

    fpsClock.tick(FPS)

    degrees += 1
I played around with the code using transform.rotate, draw.rect and I watched youtube videos, but i can't use rotate with draw.rect, i make the image fly off the screen or I just have different version of this problem and I don't want to load an image I want to create a rectangle.

Any help is welcomed
thank you
Reply


Messages In This Thread
Rotating a rectangle - by CompleteNewb - Aug-23-2021, 09:20 PM
RE: Rotating a rectangle - by deanhystad - Aug-24-2021, 09:54 AM
RE: Rotating a rectangle - by CompleteNewb - Aug-24-2021, 04:15 PM
RE: Rotating a rectangle - by deanhystad - Aug-24-2021, 05:49 PM
RE: Rotating a rectangle - by CompleteNewb - Aug-24-2021, 06:19 PM
RE: Rotating a rectangle - by deanhystad - Aug-24-2021, 08:22 PM
RE: Rotating a rectangle - by BashBedlam - Aug-24-2021, 09:46 PM
RE: Rotating a rectangle - by CompleteNewb - Aug-24-2021, 11:30 PM
RE: Rotating a rectangle - by Windspar - Aug-25-2021, 04:15 AM
RE: Rotating a rectangle - by deanhystad - Aug-25-2021, 03:47 PM
RE: Rotating a rectangle - by CompleteNewb - Aug-25-2021, 03:55 PM
RE: Rotating a rectangle - by deanhystad - Aug-25-2021, 04:34 PM
RE: Rotating a rectangle - by CompleteNewb - Aug-25-2021, 05:27 PM
RE: Rotating a rectangle - by deanhystad - Aug-25-2021, 06:44 PM
RE: Rotating a rectangle - by CompleteNewb - Aug-25-2021, 07:13 PM
RE: Rotating a rectangle - by deanhystad - Aug-25-2021, 07:32 PM
RE: Rotating a rectangle - by deanhystad - Aug-27-2021, 09:39 AM
RE: Rotating a rectangle - by deanhystad - Aug-27-2021, 11:42 AM
RE: Rotating a rectangle - by Windspar - Aug-27-2021, 05:18 PM
RE: Rotating a rectangle - by CompleteNewb - Aug-28-2021, 03:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Surface and rectangle in pygame Fabrizio_fg 6 2,372 May-27-2023, 09:15 AM
Last Post: Fabrizio_fg
  Make rectangle snap to other rectangle corners Pedroski55 2 4,399 Aug-13-2021, 09:59 PM
Last Post: Pedroski55
  [PyGame] Rotating image issue Evoluxman 8 6,216 Oct-12-2019, 12:54 PM
Last Post: Evoluxman
  [PyGame] Rectangle keeps teleporting? keyfive 1 3,228 Jun-27-2018, 11:49 PM
Last Post: sonnekrieger7

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020