# ==============================================================================
"""GRID : create some grids with several color or black/white patterns"""
# ==============================================================================
__author__  = "Christophe Schlick modified by Philippe Blasi"
__version__ = "0.0" # skeleton version
__date__    = "2022-11-12"
# ==============================================================================
from ezTK import *
# ------------------------------------------------------------------------------
def stripes(width:int=400, height:int=400, rows:int=40) -> None:
  """alternate black and white horizontal stripes"""
  win = Win(title='STRIPES') # create the main window
  colors = ('#000','#FFF') # store black and white colors in a tuple
  # calculer la largeur et la hauteur des briques
  # à partir de width, height et rows
  brick_width = width
  brick_height = height // rows
  
  for loop in range(rows):
    # if loop%2 == 0:
    #  Brick(win, width=brick_width, height=brick_height, bg='#000')
    # else:
    #  Brick(win, width=brick_width, height=brick_height, bg='#FFF')

    Brick(win, width=brick_width, height=brick_height, bg=colors,state= loop) # loop%2 est optionel
                                                              # car il est appliqué automatiquement
  win.loop() # start interaction loop
# ------------------------------------------------------------------------------
def colorstripes(width:int=400, height:int=400, rows:int=40) -> None:
  """alternate color stripes using six colors"""
  win = Win(title='COLORSTRIPES')
  colors = ('#F00','#0F0','#00F','#0FF','#F0F','#FF0') # define color set
  # calculer la largeur et la hauteur des briques
  # à partir de width, height et rows
  brick_width = width
  brick_height = height // rows
  
  for loop in range(rows):  
    Brick(win, width=brick_width, height=brick_height, bg=colors,state=loop) # loop%6 est optionel
                                                              # car il est appliqué automatiquement
  win.loop()
# ------------------------------------------------------------------------------
def chessboard(width:int=400, height:int=400, cols:int=8, rows:int=8) -> None:
  """create black and white chessboard"""
  win = Win(title='CHESSBOARD',fold=cols) # ajouter ici le fold pour la passage à la ligne pour avoir une grille

  colors = ('#000','#FFF') # store black and white colors in a tuple
  # calculer la largeur et la hauteur des briques
  # à partir de width, height et rows
  brick_width = width // cols  # <=== ajouter le calcul de la largeur des briques
  brick_height = height // rows
  
  for row in range(rows):
    for col in range(cols):
      brick_state = (row+col)%2
      Brick(win, width=brick_width, height=brick_height, bg=colors, state=brick_state) 

  win.loop()
# ------------------------------------------------------------------------------
def colorboard(width:int=400, height:int=400, cols:int=8, rows:int=8) -> None:
  """create six color checkerboard"""
  win = Win(title='COLORBOARD',op=2, fold=cols)

  colors = ('#F00','#0F0','#00F','#0FF','#F0F','#FF0') # define color set
  # calculer la largeur et la hauteur des briques
  # à partir de width, height et rows
  brick_width = width // cols  # <=== ajouter le calcul de la largeur des briques
  brick_height = height // rows
  
  for row in range(rows):
    for col in range(cols):
      brick_state = (row+col)%6
      Brick(win, width=brick_width, height=brick_height, bg=colors, border=2, state=brick_state) 

  win.loop()
# ------------------------------------------------------------------------------
def boxes(width:int=400, height:int=400, cols:int=13, rows:int=13) -> None:
  """create concentric black and white boxes"""
  win = Win(title='BOXES')
  # TODO
  win.loop()
# ------------------------------------------------------------------------------
def colorboxes(width:int=400, height:int=400, rows:int=13, cols:int=13) -> None:
  """create concentric color boxes"""
  win = Win(title='COLORBOXES')
  # TODO
  win.loop()
# ==============================================================================
if __name__ == "__main__":
  #stripes()
  #colorstripes()
  # chessboard()
  #chessboard(400,400,8,8)
  colorboard()
  #boxes()
  #colorboxes()
# ==============================================================================
