Created
December 13, 2023 20:11
-
-
Save BaileySimrell/929cd59177429b4e07a9378b5e7de130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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