import random
# Variáveis globais
# Configurações da imagem, aqui eu informo o tamanho da grade e o tamanho que eu quero que tenham os quadrados.
image_width = 3200
image_height = 410
square_size = 5
# Configurações da imagem, aqui eu informo o tamanho da grade e o tamanho que eu quero que tenham os quadrados.
image_width = 3200
image_height = 410
square_size = 5
def setup():
size(image_width, image_height) # Cria a grade
background(255)
no_loop()
size(image_width, image_height) # Cria a grade
background(255)
no_loop()
def draw():
# Definir o número de linhas e colunas com base no tamanho dos quadrados
num_columns = image_width // square_size
num_rows = image_height // square_size
# Definir o número de linhas e colunas com base no tamanho dos quadrados
num_columns = image_width // square_size
num_rows = image_height // square_size
# Desenhar os quadrados
for row in range(num_rows): # Por linha
for col in range(num_columns): # Por coluna
x0 = col * square_size
y0 = row * square_size
x1 = x0 + square_size
y1 = y0 + square_size
color_square = color(0) if random.random() < 0.5 else color(255) # Faz o sorteio de cor
fill(color_square) # Pinta de preto ou branco
rect(x0, y0, square_size, square_size) # Desenha o quadrado
for row in range(num_rows): # Por linha
for col in range(num_columns): # Por coluna
x0 = col * square_size
y0 = row * square_size
x1 = x0 + square_size
y1 = y0 + square_size
color_square = color(0) if random.random() < 0.5 else color(255) # Faz o sorteio de cor
fill(color_square) # Pinta de preto ou branco
rect(x0, y0, square_size, square_size) # Desenha o quadrado
# Salva a imagem
save_frame("grid_image.png")
save_frame("grid_image.png")