# ParquetSol.py
# The CS1110 profs, spring 2016 (cs-1110profs-L@cornell.edu)
# Feb 2016

""" Draws various Parquet tiles and floors."""

from SimpleGraphics import *


def DrawParquetTile(a,b,H,C1,C2):
    """ Draws a 5-by-5 Parquet tile centered at (a,b).
    If H is True, then the strips are horizontal.
    If H is False, then the strips are vertical.
    Strips 1, 3, and 5 have color C1.
    Strips 2 and 4 have color C2.

    PreC: a and b are floats or ints. C1 and C2 are rgb lists,
    and H is Boolean.
    """
    if H:
        # Horizontal strips.
        DrawRect(a,b-2,5,1,FillColor=C1)  # Strip 1
        DrawRect(a,b-1,5,1,FillColor=C2)  # Strip 2
        DrawRect(a,b,5,1,  FillColor=C1)  # Strip 3
        DrawRect(a,b+1,5,1,FillColor=C2)  # Strip 4
        DrawRect(a,b+2,5,1,FillColor=C1)  # Strip 5
    else:
        # Vertical strips...
        DrawRect(a-2,b,1,5,FillColor=C1)  # Strip 1
        DrawRect(a-1,b,1,5,FillColor=C2)  # Strip 2
        DrawRect(a,b,1,5,  FillColor=C1)  # Strip 3
        DrawRect(a+1,b,1,5,FillColor=C2)  # Strip 4
        DrawRect(a+2,b,1,5,FillColor=C1)  # Strip 5

    DrawRect(a,b,5,5,EdgeColor=BLACK,FillColor=None,EdgeWidth=3)


# alternate implementation
def DrawParquetTile2(a,b,H,C1,C2):
    """ Same as DrawParquetTile
    """

    # first, assume strips will be vertical
    delta_y = 0.0 # diff in y values for consecutive strip centers
    delta_x = 1.0 # diff in x values for consecutive strip centers
    theta = 90.0  # angle of strips

    if H: # make adjustments if strips will be horizontal
        delta_y = 1.0
        delta_x = 0.0
        theta = 0.0

    # now the horizontal and vertical case can be treated identically
    DrawRect(a-2*delta_x, b-2*delta_y, 5, 1, theta, FillColor=C1)
    DrawRect(a-1*delta_x, b-1*delta_y, 5, 1, theta, FillColor=C2)
    DrawRect(a, b, 5, 1, theta, FillColor=C1)
    DrawRect(a+1*delta_x, b+1*delta_y, 5, 1, theta, FillColor=C2)
    DrawRect(a+2*delta_x, b+2*delta_y, 5, 1, theta, FillColor=C1)

    DrawRect(a,b,5,5,EdgeColor=BLACK,FillColor=None,EdgeWidth=3)


def DrawParquetFloor(a,b,H,C1,C2):
    """ Draws a 3x3 Parquet floor centered at (a,b).
    If H is True, then the center tile has horizontal strips.
    If H is False, then the center tile has vertical strips.
    Strips 1,3, and 5  of the center tile have color C1.
    Strips 2 and 4 of the center tile have color C2.

    PreC: a and b are floats or ints. C1 and C2 are rgb lists,
    and H is Boolean.
    """

    DrawParquetTile(a-5,b-5,H,C1,C2)
    DrawParquetTile(a-5,b,not H,C2,C1)
    DrawParquetTile(a-5,b+5,H,C1,C2)
    DrawParquetTile(a,b-5,not H,C2,C1)
    DrawParquetTile(a,b,H,C1,C2)
    DrawParquetTile(a,b+5,not H,C2,C1)
    DrawParquetTile(a+5,b-5,H,C1,C2)
    DrawParquetTile(a+5,b,not H,C2,C1)
    DrawParquetTile(a+5,b+5,H,C1,C2)


# alternate implementation
def DrawParquetFloor2(a,b,H,C1,C2):
    """ Same as DrawParquetFloor
    """
    # differences in x and y values for adjacent tiles
    delta_x = 5.0
    delta_y = 5.0

    # draw the copies of the middle tile
    orientation = H
    color1 = C1
    color2 = C2
    DrawParquetTile(a-delta_x, b-delta_y, orientation, color1, color2)
    DrawParquetTile(a-delta_x, b+delta_y, orientation, color1, color2)
    DrawParquetTile(a, b, orientation, color1, color2)
    DrawParquetTile(a+delta_x, b-delta_y, orientation, color1, color2)
    DrawParquetTile(a+delta_x, b+delta_y, orientation, color1, color2)

    # draw the opposites of the middle tile
    orientation = not H
    color1 = C2
    color2 = C1
    DrawParquetTile(a-delta_x, b, orientation, color1, color2)
    DrawParquetTile(a, b-delta_y, orientation, color1, color2)
    DrawParquetTile(a, b+delta_y, orientation, color1, color2)
    DrawParquetTile(a+delta_x, b, orientation, color1, color2)






# Application Script
if __name__ == '__main__':
    # The two colors
    C1 = MAGENTA
    C2 = CYAN

    # The first window.
    # Display two Parquet tiles, one with horizontal orientation
    # and the other with vertical orientation:
    MakeWindow(7,bgcolor=DARKGRAY)
    DrawParquetTile(3,0,False,C1,C2)
    DrawParquetTile(-3,0,True,C2,C1)

    # The second window.
    # Display two Parquet floors, one with horizontal orientation
    # and the other with vertical orientation.
    MakeWindow(18,bgcolor=DARKGRAY,labels=False)
    DrawParquetFloor(8,0,False,C1,C2)
    DrawParquetFloor(-8,0,True,C1,C2)

    # The third window
    # Display the Dance Floor
    MakeWindow(16,bgcolor=DARKGRAY,labels=False)
    DrawParquetFloor(-7.5,-7.5,True,C1,C2)
    DrawParquetFloor(-7.5,7.5,False,C2,C1)
    DrawParquetFloor(7.5,-7.5,False,C2,C1)
    DrawParquetFloor(7.5,7.5,True,C1,C2)

    # Display all the windows
    ShowWindow()