# 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 opc.hue import hsvToRgb
import numpy as np
import random
import math
        xs = np.array([region["x"] for region in self.regions])
        ys = np.array([region["y"] for region in self.regions])

        # find closest region to eack pixel
        for y in range(matrix.height):
            for x in range(matrix.width):
                c=self._closest(xs, ys, x, y)
                field[x,y] = self.huebase+c/self.count

        # update region coordinates
        self.regions = [{
                "dx": self._bounce(region["x"], region["dx"],  matrix.width-1),
                "dy": self._bounce(region["y"], region["dy"],  matrix.height-1),

                "x": region["x"]+region["dx"],
                "y": region["y"]+region["dy"],
            } for region in self.regions]

        # blend old and new
        if self.field is not None:
            self.field = (self.field*0.3) + (field*0.7)
        else:
            self.field = field

        # draaw
        for y in range(matrix.height):
            for x in range(matrix.width):
                matrix.drawPixel(x, y, hsvToRgb(self.field[x,y], 1, 1))

        for region in self.regions:

# 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/voronoi.py
from ._baseclass import ArtBaseClass
from opc.hue import hsvToRgb
import numpy as np
import random
import math

        xs = np.array([region["x"] for region in self.regions])
        ys = np.array([region["y"] for region in self.regions])

        # find closest region to eack pixel
        for y in range(matrix.height):
            for x in range(matrix.width):
                c=self._closest(xs, ys, x, y)
                field[x,y] = self.huebase+c/self.count

        # update region coordinates
        self.regions = [{
                "dx": self._bounce(region["x"], region["dx"],  matrix.width-1),
                "dy": self._bounce(region["y"], region["dy"],  matrix.height-1),

                "x": region["x"]+region["dx"],
                "y": region["y"]+region["dy"],
            } for region in self.regions]

        # blend old and new
        if self.field is not None:
            self.field = (self.field*0.3) + (field*0.7)
        else:
            self.field = field

        # draaw
        for y in range(matrix.height):
            for x in range(matrix.width):
                matrix.drawPixel(x, y, hsvToRgb(self.field[x,y], 1, 1))

        for region in self.regions:

            matrix.drawPixel(region["x"], region["y"], hsvToRgb(1,  0, 0))