Skip to content

Instantly share code, notes, and snippets.

@villares
Last active March 30, 2020 18:26
Show Gist options
  • Save villares/219b457c82adfd73b6664aa10cb681f2 to your computer and use it in GitHub Desktop.
Save villares/219b457c82adfd73b6664aa10cb681f2 to your computer and use it in GitHub Desktop.
@anniek_p 's mindblowingly simple yet fiendishly difficult #mathartchallenge
"""
Annie Perkins Math Art Challenge
https://twitter.com/anniek_p/status/1244220881347502080
Peter Farrell
https://github.com/hackingmath/pygame_sketches/blob/master/binary_grid_challenge.py
Alexandre Villares
https://gist.github.com/villares/219b457c82adfd73b6664aa10cb681f2
"""
from random import choice, randint
# define constants
BLACK = (0, 0, 0)
CYAN = (0, 255, 255)
def setup():
global len_line, offset1_list, offset2_list
size(600, 600)
len_line = width / rows
rows, cols = 30, 30
offset1_list = [choice([0, 1]) for i in range(rows)]
offset2_list = [choice([0, 1]) for i in range(cols)]
print(offset1_list)
print(offset2_list)
def draw_lines_row(y, offset):
"""draws lines every other square"""
for c in range(0, cols, 2):
line(len_line * (c + offset), y, len_line * (c + 1 + offset), y)
def draw_lines_col(x, offset):
"""draws lines every other square"""
for r in range(0, rows, 2):
line(x, len_line * (r + offset), x, len_line * (r + 1 + offset))
def draw():
# fill the screen with background color
background(*CYAN)
idx = randint(0, rows - 1)
if frameCount % 6 == 0:
offset1_list[idx] = 1 - offset1_list[idx]
if frameCount % 6 == 3:
offset2_list[idx] = 1 - offset2_list[idx]
for r in range(rows):
for c in range(cols):
draw_lines_row(c*len_line, offset1_list[c])
draw_lines_col(r*len_line, offset2_list[r])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment