Skip to content

Instantly share code, notes, and snippets.

@BaileySimrell
Created December 13, 2023 20:11
Show Gist options
  • Save BaileySimrell/929cd59177429b4e07a9378b5e7de130 to your computer and use it in GitHub Desktop.
Save BaileySimrell/929cd59177429b4e07a9378b5e7de130 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
import random
# Initialize variables
n_rows = 42
n_cols = 42
total_squares = n_rows * n_cols
half_squares = total_squares // 2
# Create a list of colors, half 0s and half 1s
colors = [0] * half_squares + [1] * half_squares
# Shuffle the colors randomly
random.shuffle(colors)
# Create a numpy array for the grid
grid = np.array(colors).reshape(n_rows, n_cols)
# Function to display the grid
def display_grid(grid):
plt.figure(figsize=(8, 8))
plt.imshow(grid, cmap='gray', interpolation='nearest')
plt.axis('off')
plt.show()
# Display the grid
display_grid(grid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment