Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

grid in 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_HEIGHT, WINDOW_WIDTH))
    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(WINDOW_WIDTH):
        for y in range(WINDOW_HEIGHT):
            rect = pygame.Rect(x*blockSize, y*blockSize,
                               blockSize, blockSize)
            pygame.draw.rect(SCREEN, WHITE, rect, 1)
Comment

PREVIOUS NEXT
Code Example
Python :: human readable time difference python 
Python :: how to get the contents of a txt file in python 
Python :: get last year of today python 
Python :: pytorch tensor change dimension order 
Python :: show jpg in jupyter notebook 
Python :: create virtualenv in pythonanywhere 
Python :: read os.system output python 
Python :: how to print a random part of a list in python 
Python :: installing wxpython on windows 10 
Python :: python datetime add minutes 
Python :: how to add list item to text file python 
Python :: squared sum of all elements in list python 
Python :: f-string ponto decimal python 
Python :: np array to df 
Python :: update my anaconda 
Python :: set window size tkinter 
Python :: edit json file python 
Python :: panda get rows with date range 
Python :: columns to dictionary pandas 
Python :: tqdm in for loop 
Python :: to extract out only year month from a date column in pandas 
Python :: plotly write html 
Python :: how to generate requirements.txt django 
Python :: how to take list of float as input in python 
Python :: ipywidgets pip 
Python :: how to pass header in requests 
Python :: r squared python 
Python :: colab tqdm import 
Python :: python nltk tokenize 
Python :: multipl excel sheets in pandas 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =