Skip to content

Instantly share code, notes, and snippets.

@gcorreaq
Last active January 1, 2016 15:59
Show Gist options
  • Save gcorreaq/8167379 to your computer and use it in GitHub Desktop.
Save gcorreaq/8167379 to your computer and use it in GitHub Desktop.
import numpy
def squares(matrix, square_size):
paint = False
for row in xrange(len(matrix)):
# Only in the borders of the square, we change the switch to paint
if row % square_size == 0:
paint = not paint
# We need to store the initial status of the row, because it
# defines the behaviour of the pixels in the entire row. If
# we don't store it, the status of the next row depends on the
# status of the last pixel in this rows (and the patterns becomes
# really weird!)
initial_status = paint
for col in xrange(len(matrix[row])):
# Only in the borders of the square, we change the switch to paint
if col % square_size == 0:
paint = not paint
if paint:
matrix[row][col] = 0
paint = initial_status
matrix = numpy.ones((10, 10))
squares(matrix, input("Square size: "))
print matrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment