# 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/utils/lfsr.py
# @timefunc
# def compoundLfsr(slots):
#     """
#     Combine a number of LFSRs to support an arbitary range of
#     once-visit values, most of the heavy lifting is done in a
#     class.
# 
#     figure out largest power of two that is smaller than places
#     add as many of these to the pool that fit, this is a bucket.
#     take the remainder and repeat until there is nothing left.
# 
#     while generating visit each bucket in round-robin sequence,
#     until all of the buckets report empty.
#     """
#     pool = LfsrBucket(slots)
#     while True:
#         failures = 0
#         while True:
#             value = pool.get()
#             if value is not None:
#                 yield value
#                 break
# 
#             failures += 1
#             if failures == pool.buckets():
#                 # nome of the buckets have anything left, the
#                 # supply of values is exhausted
#                 return


from ._baseclass import ArtBaseClass
from opc.hue import hsvToRgb
from random import random
from .utils.lfsr import compoundLfsr



HUEINCYCLES = 8


class Art(ArtBaseClass):

    description = "Use an LFSR to 'randomly' fill the display"

    def __init__(self, matrix, config):
        pass

    def start(self, matrix):
        # we could probably shuffle() up a range, but that sounds like
        # it'd be less of a challenge :)
        self.random = compoundLfsr(matrix.numpix)
        self.hue = random()
        matrix.clear()

    def refresh(self, matrix):
        try:
            pos = next(self.random)
        except:

# 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/utils/lfsr.py
# @timefunc
# def compoundLfsr(slots):
#     """
#     Combine a number of LFSRs to support an arbitary range of
#     once-visit values, most of the heavy lifting is done in a
#     class.
# 
#     figure out largest power of two that is smaller than places
#     add as many of these to the pool that fit, this is a bucket.
#     take the remainder and repeat until there is nothing left.
# 
#     while generating visit each bucket in round-robin sequence,
#     until all of the buckets report empty.
#     """
#     pool = LfsrBucket(slots)
#     while True:
#         failures = 0
#         while True:
#             value = pool.get()
#             if value is not None:
#                 yield value
#                 break
# 
#             failures += 1
#             if failures == pool.buckets():
#                 # nome of the buckets have anything left, the
#                 # supply of values is exhausted
#                 return


# Path: art/scatter.py
from ._baseclass import ArtBaseClass
from opc.hue import hsvToRgb
from random import random
from .utils.lfsr import compoundLfsr




HUEINCYCLES = 8


class Art(ArtBaseClass):

    description = "Use an LFSR to 'randomly' fill the display"

    def __init__(self, matrix, config):
        pass

    def start(self, matrix):
        # we could probably shuffle() up a range, but that sounds like
        # it'd be less of a challenge :)
        self.random = compoundLfsr(matrix.numpix)
        self.hue = random()
        matrix.clear()

    def refresh(self, matrix):
        try:
            pos = next(self.random)
        except:

            self.random = compoundLfsr(matrix.numpix)