# Tessellations program from codex import * my_colors = [RED, BLUE, GREEN, PINK, ORANGE, MAGENTA, YELLOW, DARK_GREEN, CYAN, PURPLE, WHITE] # define a brick def brick(x, y, color): display.fill_rect(x, y, 50, 20, color) display.draw_rect(x, y, 50, 20, WHITE) def skew(x, y, color): display.fill_rect(x, y, 50, 20, color) display.fill_rect(x+25, y+20, 50, 20, color) def halfcross(x, y, color): display.fill_rect(x, y+10, 10, 10, color) display.fill_rect(x+10, y, 10, 30, color) def halfcross_big(x, y, color): display.fill_rect(x, y+20, 20, 20, color) display.fill_rect(x+20, y, 20, 60, color) def triangle(x, y, color): display.draw_line(x, y, x+40, y, color) display.draw_line(x, y, x+20, y+20, color) display.draw_line(x+20, y+20, x+40, y, color) def flipped(x, y, color): display.draw_line(x, y, x+40, y, color) display.draw_line(x, y, x+20, y-20, color) display.draw_line(x+20, y-20, x+40, y, color) def tessell_bricks(x, y, index): for row in range(6): for column in range(5): brick(x, y, my_colors[index]) x = x + 50 index = index + 1 if index == len(my_colors): index = 0 x = -25 y = y + 20 for column in range(6): brick(x, y, my_colors[index]) x = x + 50 index = index + 1 if index == len(my_colors): index = 0 x = 0 y = y + 20 def tessell_skew(x, y, index): for row in range(3): for column in range(6): skew(x, y, my_colors[index]) x = x + 50 index = index + 1 if index == len(my_colors): index = 0 x = -25 y = y + 40 for column in range(6): skew(x, y, my_colors[index]) x = x + 50 index = index + 1 if index == len(my_colors): index = 0 x =-50 y = y + 40 def tessell_halfcross(x, y, index): for row in range(12): for column in range(12): halfcross(x, y, my_colors[index]) x = x + 20 index = index + 1 if index == len(my_colors): index = 0 x = -10 y = y + 20 for column in range(13): halfcross(x, y, my_colors[index]) x = x + 20 index = index + 1 if index == len(my_colors): index = 0 x = 0 y = y + 20 def tessell_halfcross_big(x, y, index): for row in range(4): for column in range(12): halfcross_big(x, y, my_colors[index]) x = x + 40 index = index + 1 if index == len(my_colors): index = 0 x = -20 y = y + 40 for column in range(13): halfcross_big(x, y, my_colors[index]) x = x + 40 index = index + 1 if index == len(my_colors): index = 0 x = 0 y = y + 40 def tessell_triangle(x, y, index): for row in range(12): for column in range(6): triangle(x, y, my_colors[index]) x = x + 40 index = index + 1 if index == len(my_colors): index = 0 x = -20 y = y+20 for column in range(7): flipped(x, y, my_colors[index]) x = x + 40 index = index + 1 if index == len(my_colors): index = 0 x = 0 # Main program while True: if buttons.was_pressed(BTN_A): display.clear() tessell_bricks(0, 0, 0) if buttons.was_pressed(BTN_B): display.clear() tessell_skew(-50, 0, 0) if buttons.was_pressed(BTN_R): display.clear() tessell_halfcross(0, -10, 0) if buttons.was_pressed(BTN_U): display.clear() tessell_halfcross_big(0, -20, 0) if buttons.was_pressed(BTN_L): display.clear() tessell_triangle(0, 0, 0)