Set a point on the image to act as rotate point Pygame.transform.rotate()
Question: I am newbie to both python and pygame. I want to rotate a rectangle about a
point other than center. My code so far is :

    
    
        import pygame
        pygame.init()
        w = 640
        h = 480
        degree =45
        screen = pygame.display.set_mode((w,h))
        surf = pygame.Surface((25, 100))
        surf.fill((255, 255, 255))
        surf.set_colorkey((255, 0, 0))
        bigger = pygame.Rect(0, 0, 25, 100)
        pygame.draw.rect(surf, (100, 0, 0), bigger)
        rotatedSurf = pygame.transform.rotate(surf, degree)
        screen.blit(rotatedSurf, (400,300))
        running = True
        while running:
            event = pygame.event.poll()
            if event.type ==pygame.QUIT:
                running = False
            pygame.display.flip()
    
    

I can change the degree to get different rotation but the rotation is about
center. I want to set a point other than center of the rectangle as a rotate
point.

Please help. Thanks


Answer: I think you have to make a function of your own for that.

If you make a Vector class it's much easier.

Maybe something like:

    
    
    def rotate(surf, angle, pos):
        pygame.transform.rotate(surf, angle)
        rel_pos = surf.blit_pos.sub(pos)
        new_rel_pos = rel_pos.set_angle(rel_pos.get_angle() + angle)
        surf.blit_pos = pos.add(new_rel_pos)
    

So there you have it.The only thing you have to do is the Vector class with
the methods 'add()', 'sub()', 'get_angle()' and 'set_angle()'. If you are
strugling just google for help.

In the end you'll end up with a nice Vector class that you can expand and use
in other projects.

