# ==============================================================================
"""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 hauteurs des briques
  brick_width  = width
  brick_height = height // rows
  
  # faire une boucle sur le nombre de lignes
  for loop in range(rows):
    # choisir l'état pour la brique : 0 ==> noir; 1 ==> blanc
    brick_state = loop % 2
    Brick(win, width=brick_width, height=brick_height, bg=colors, state=brick_state)
  
  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')
  # calculer la largeur et la hauteurs des briques
  brick_width  = width
  brick_height = height // rows
  
  # faire une boucle sur le nombre de lignes
  for loop in range(rows):
    brick_state = loop % 6
    Brick(win, width=brick_width, height=brick_height, bg=colors, state=brick_state)
    
  win.loop()
# ------------------------------------------------------------------------------
def chessboard(width:int=400, height:int=400, cols:int=8, rows:int=8) -> None:
  """create black and white chessboard"""
  # ajouter un paramètre fold à la fenêtre pour obtenir une grille
  win = Win(title='CHESSBOARD', fold=cols)

  colors = ('#000','#FFF') # store black and white colors in a tuple
  # calculer la largeur et la hauteurs des briques
  brick_width  = width  // cols
  brick_height = height // rows
  
  for row in range(rows):
    for col in range(cols):
      # choisir l'état pour la brique : 0 ==> noir; 1 ==> blanc
      # trouver la relation qui à partir de la ligne et de la colonne permet d'avoir
      # le bon état
      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"""
  # ajouter un paramètre fold à la fenêtre pour obtenir une grille
  # ajouter un paramètre op (pour outer padding) pour espacer les éléments
  win = Win(title='COLORBOARD', op=2, fold=cols)
  colors = ('#F00','#0F0','#00F','#0FF','#F0F','#FF0')
  # calculer la largeur et la hauteurs des briques
  brick_width  = width  // cols
  brick_height = height // rows
  
  for row in range(rows):
    for col in range(cols):
      # choisir l'état pour la brique : 0 ==> noir; 1 ==> blanc
      # trouver la relation qui à partir de la ligne et de la colonne permet d'avoir
      # le bon état
      brick_state = (row+col) % 6
      Brick(win, width=brick_width, height=brick_height, bg=colors, border=3, 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()
  colorboard()
  #boxes()
  #colorboxes()
# ==============================================================================
