# Path: opc/hue.py
# @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 math import sqrt
from opc.hue import hsvToRgb




class Art(ArtBaseClass):

    description = "Slow transition of hues across the display"

    def __init__(self, matrix, config):
        self.base = 0

    def start(self, matrix):
        pass

    def refresh(self, matrix):
        self.base += 4
        h = matrix.height - 1

        for x in range(matrix.width):
            hue = (self.base+32*x) / (sqrt(matrix.numpix) * 64.0)
            for y in range(matrix.height):
                sat = min(1, 0.25 + (1.5*y)/h)
                val = min(1, 0.25 + (1.5*(h-y)/h))
                matrix.drawPixel(x, y, hsvToRgb(hue, sat, val))

    def interval(self):

# Path: opc/hue.py
# @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/rainbow.py
from ._baseclass import ArtBaseClass
from math import sqrt
from opc.hue import hsvToRgb





class Art(ArtBaseClass):

    description = "Slow transition of hues across the display"

    def __init__(self, matrix, config):
        self.base = 0

    def start(self, matrix):
        pass

    def refresh(self, matrix):
        self.base += 4
        h = matrix.height - 1

        for x in range(matrix.width):
            hue = (self.base+32*x) / (sqrt(matrix.numpix) * 64.0)
            for y in range(matrix.height):
                sat = min(1, 0.25 + (1.5*y)/h)
                val = min(1, 0.25 + (1.5*(h-y)/h))
                matrix.drawPixel(x, y, hsvToRgb(hue, sat, val))

    def interval(self):

        return 100