how do i cover windows with scalable rects in python?

Use 2 nested loops and the built-in range function:

import pygame
import sys

width, height = 750, 750
window = pygame.display.set_mode((width, height))

scale = 1
scroll_scale = .05
while True:
    graph_size = 50 * scale
    graph_count = width / graph_size
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 4:
                scale += scroll_scale
            elif event.button == 5 and scale > 0:
                scale -= scroll_scale

    window.fill((255,255,255))
    size = round(graph_size)
    for x in range(0, width + size, size):
        for y in range(0, height + size, size):
            c = (0,255,0) if (((x + y) // size) % 2) == 0 else  (127, 127, 127)
            pygame.draw.rect(window, c, (x, y, size, size))
    pygame.display.update()

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top