# Path: opc/hue.py
# def getHueGen(step=0.05, hue=0):
#     """
#     Generator that returns a stream of shades as hues
#     """
#     while True:
#         hue = fmod(hue + step, 1)
#         yield hue
# 
# @mwt(timeout=20)
# @timefunc
# def hsvToRgb(h, s=1.0, v=1.0, rainbow=True):
#     """
#     Convert a (h, s, v) value to the (r, g, b) color space. By default,
#     we use a more cpu-intense method to curve the hue ramps above the
#     typical linear, with a view to evening out the visible range of yellow,
#     cyan, and purple.
# 
#     This method takes h, s, and v values in range 0..1 and returns r, g,
#     and b values in range 0..255.
#     """
#     if rainbow:
#         return [sin(c*pi/2)*255 for c in colorsys.hsv_to_rgb(h, s, v)]
# 
#     return [c*255 for c in colorsys.hsv_to_rgb(h, s, v)]


from ._baseclass import ArtBaseClass
from opc.hue import getHueGen, hsvToRgb
from math import sqrt


class Art(ArtBaseClass):

    description = "A silly chess board"

    def __init__(self, matrix, config):
        self.hue = getHueGen(0.0005)

    def start(self, matrix):
        matrix.clear(C_BACKGROUND)

    def refresh(self, matrix):
        hue = next(self.hue)

        # pixels per squre 
        pps = int((sqrt(matrix.numpix)-1)/GRIDSIZE)

        xcorner = matrix.midWidth - pps*(GRIDSIZE/2)
        ycorner = matrix.midHeight - pps*(GRIDSIZE/2)

        matrix.drawRect(xcorner-1, ycorner-1,
                        pps*GRIDSIZE+1, pps*GRIDSIZE+1, C_BORDER)

        for x in range(GRIDSIZE):
            for y in range(GRIDSIZE):
                black = (x & 1) ^ (y & 1)
                if black:
                    color = hsvToRgb(hue, s=0.7, v=0.5)
                else:

# Path: opc/hue.py
# def getHueGen(step=0.05, hue=0):
#     """
#     Generator that returns a stream of shades as hues
#     """
#     while True:
#         hue = fmod(hue + step, 1)
#         yield hue
# 
# @mwt(timeout=20)
# @timefunc
# def hsvToRgb(h, s=1.0, v=1.0, rainbow=True):
#     """
#     Convert a (h, s, v) value to the (r, g, b) color space. By default,
#     we use a more cpu-intense method to curve the hue ramps above the
#     typical linear, with a view to evening out the visible range of yellow,
#     cyan, and purple.
# 
#     This method takes h, s, and v values in range 0..1 and returns r, g,
#     and b values in range 0..255.
#     """
#     if rainbow:
#         return [sin(c*pi/2)*255 for c in colorsys.hsv_to_rgb(h, s, v)]
# 
#     return [c*255 for c in colorsys.hsv_to_rgb(h, s, v)]


# Path: art/RETIRED/chess.py
from ._baseclass import ArtBaseClass
from opc.hue import getHueGen, hsvToRgb
from math import sqrt



class Art(ArtBaseClass):

    description = "A silly chess board"

    def __init__(self, matrix, config):
        self.hue = getHueGen(0.0005)

    def start(self, matrix):
        matrix.clear(C_BACKGROUND)

    def refresh(self, matrix):
        hue = next(self.hue)

        # pixels per squre 
        pps = int((sqrt(matrix.numpix)-1)/GRIDSIZE)

        xcorner = matrix.midWidth - pps*(GRIDSIZE/2)
        ycorner = matrix.midHeight - pps*(GRIDSIZE/2)

        matrix.drawRect(xcorner-1, ycorner-1,
                        pps*GRIDSIZE+1, pps*GRIDSIZE+1, C_BORDER)

        for x in range(GRIDSIZE):
            for y in range(GRIDSIZE):
                black = (x & 1) ^ (y & 1)
                if black:
                    color = hsvToRgb(hue, s=0.7, v=0.5)
                else:

                    color = hsvToRgb(hue + 0.2, v=0.8)