Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

2d grid python pygame

import pygame

BLACK = (0, 0, 0)
WHITE = (200, 200, 200)
WINDOW_HEIGHT = 400
WINDOW_WIDTH = 400


pygame.init()
SCREEN = pygame.display.set_mode((WINDOW_HEIGHT, WINDOW_WIDTH))
CLOCK = pygame.time.Clock()
SCREEN.fill(BLACK)


def draw_grid():
    block_size = 20
    for x in range(WINDOW_WIDTH):
        for y in range(WINDOW_HEIGHT):
            rect = pygame.Rect(x*block_size, y*block_size,
                               block_size, block_size)
            pygame.draw.rect(SCREEN, WHITE, rect, 1)


while True:
    draw_grid()
    pygame.display.flip()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
Comment

2d grid python pygame


BLACK = (0, 0, 0)
WHITE = (200, 200, 200)
WINDOW_HEIGHT = 400
WINDOW_WIDTH = 400


def main():
    global SCREEN, CLOCK
    pygame.init()
    SCREEN = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
    CLOCK = pygame.time.Clock()
    SCREEN.fill(BLACK)

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

        pygame.display.update()


def drawGrid():
    blockSize = 20 #Set the size of the grid block
    for x in range(0, WINDOW_WIDTH, blockSize):
        for y in range(0, WINDOW_HEIGHT, blockSize):
            rect = pygame.Rect(x, y, blockSize, blockSize)
            pygame.draw.rect(SCREEN, WHITE, rect, 1)

Comment

PREVIOUS NEXT
Code Example
Python :: 7616*75 
Python :: python print to string 
Python :: visual studio code python indent shortcut 
Python :: sorting-a-dictionary-by-value-then-by-key 
Python :: get last item in array python 
Python :: autoencoder for classification keras 
Python :: numpy slice double colon stack overflow 
Python :: best movies to watch once in lifetime 2000 
Python :: python3 array 
Python :: Return a new RDD containing the distinct elements in this RDD. 
Python :: visualizzare csv in pycharm pandas read_csv 
Python :: assign multiple vabies in one line 
Python :: python code for calculating probability of random variable 
Python :: pandas drop a list of rows 
Python :: how to pairwise permute in python 
Python :: specify dtype when creating array 
Python :: dataframe remove first row 
Python :: print(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) print(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) 
Python :: list of google colab deep learning tutorial 
Python :: pythonpath manager spyder 
Python :: Deques in python3 
Python :: indentation error python 
Python :: what is norways politics 
Python :: without using sum add item in list python 
Python :: Clasificador Lineal 
Python :: python double indentation 
Python :: Why do we put r before a path name in Python 
Python :: java to python conversion 
Python :: pdf to excel python 
Python :: 2D array questions python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =