move origin to the left bottom corner
时间: 2024-03-20 13:44:38 浏览: 59
To move the origin to the left bottom corner, you can modify the coordinate system of your graphics environment. In most cases, this can be done by adjusting the y-axis scaling factor and offset. Specifically, you can set the y-axis scaling factor to a negative value, which will vertically flip the coordinate system, and then add the height of the graphics window to the y-axis offset, which will shift the origin to the left bottom corner.
Here's an example in Python using the Pygame library:
```
import pygame
# initialize Pygame
pygame.init()
# create a graphics window
width, height = 640, 480
screen = pygame.display.set_mode((width, height))
# flip the y-axis and shift the origin
pygame.display.flip()
pygame.display.glScalef(1, -1)
pygame.display.glTranslatef(0, -height, 0)
# draw a rectangle at (0, 0)
rect = pygame.Rect(0, 0, 50, 50)
pygame.draw.rect(screen, (255, 255, 255), rect)
# update the screen
pygame.display.flip()
# run the event loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
```
In this example, we first create a graphics window with the specified width and height. Then, we flip the y-axis and shift the origin using the `glScalef` and `glTranslatef` functions from the Pygame library. Finally, we draw a white rectangle at the original position (0, 0) and update the screen. The event loop enables the window to stay open until the user closes it.
阅读全文