# Tessellations program # starter code 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+20, 20, 20, color) display.fill_rect(x+20, y, 20, 60, color) def triangle(x, y, color): display.draw_line(x, y, x+60, y, color) display.draw_line(x, y, x+30, y+30, color) display.draw_line(x+30, y+30, x+60, y, color) def flipped(x, y, color): display.draw_line(x, y, x+60, y, color) display.draw_line(x, y, x+30, y-30, color) display.draw_line(x+30, y-30, x+60, y, color) def my_shape(x, y, color): pass # programmers own shape def tessell_bricks(x, y, index): toggle = False for row in range(11): for column in range(6): brick(x, y, my_colors[index]) x = x + 50 index = index + 1 if index == len(my_colors): index = 0 toggle = not toggle if toggle: x = -25 else: x = 0 y = y + 20 def tessell_skew(x, y, index): toggle = False for row in range(6): for column in range(6): skew(x, y, my_colors[index]) x = x + 50 index = index + 1 if index == len(my_colors): index = 0 toggle = not toggle if toggle: x = -25 else: x = -50 y = y + 40 def tessell_halfcross(x, y, index): toggle = False for row in range(7): for column in range(7): halfcross(x, y, my_colors[index]) x = x + 40 index = index + 1 if index == len(my_colors): index = 0 toggle = not toggle if toggle: x = -20 else: x = 0 y = y + 40 def tessell_triangle(x, y, index): toggle = False for row in range(16): for column in range(5): if toggle: flipped(x, y, my_colors[index]) else: triangle(x, y, my_colors[index]) x = x + 60 index = index + 1 if index == len(my_colors): index = 0 toggle = not toggle if toggle: x = -31 y = y + 31 else: x = 0 def tessell_my_shape(x, y, index): my_shape(x, y, my_colors[index]) def menu(): display.clear() display.print("--Menu--") display.print("A - bricks") display.print("B - skew") display.print("R - half cross") display.print("L - triangle") display.print("U - my shape") display.print() display.print("A to begin") while True: if buttons.was_pressed(BTN_A): break # Main program menu() 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, -20, 0) if buttons.was_pressed(BTN_L): display.clear() tessell_triangle(0, 0, 0) if buttons.was_pressed(BTN_U): display.clear() tessell_my_shape(0, 0, 0) if buttons.was_pressed(BTN_D): break # Program end display.clear() display.print("The end")