# Path: opc/nphue.py
# @timefunc
# def h_to_rgb(h, sat=1, val=255.0):
#     # Local variation of hsv_to_rgb that only cares about a variable
#     # hue, with (s,v) assumed to be constant
#     # h should be a numpy array with values between 0.0 and 1.0
#     # hsv_to_rgb returns an array of uints between 0 and 255.
#     s = np.full_like(h, sat)
#     v = np.full_like(h, val)
#     hsv = np.dstack((h, s, v))
# 
#     return hsv_to_rgb(hsv)


from ._baseclass import ArtBaseClass
from opc.nphue import h_to_rgb
import numpy as np
class Art(ArtBaseClass):

    description = "Classic plasma (almost)"

    def __init__(self, matrix, config):
        ones = np.ones(matrix.numpix).reshape((matrix.height, matrix.width))
        self.x = ones*np.arange(matrix.width)
        self.y = np.flipud(np.rot90(np.rot90(ones)*np.arange(matrix.height)))

        self.base = 128000

    def start(self, matrix):
        pass

    def _dist(self, a, b, c, d):
        return np.sqrt((c-a)*(c-a)+(d-b)*(d-b))

    def refresh(self, matrix):

        xb = self.x + self.base
        yb = self.y + self.base

        c1 = self._dist(xb, self.y, 128.0, 128.0) / (matrix.smallest/2)
        c2 = self._dist(self.y, self.y, 64.0, 64.0) / (matrix.smallest/2)
        c3 = self._dist(self.x, yb / 7, 192.0, 64) / (matrix.smallest/2)
        c4 = self._dist(self.y, self.x, 192.0, 100.0) / (matrix.smallest/2)

        hue = np.sum(np.sin(c) for c in (c1, c2, c3, c4))
        hue = np.fmod(np.fabs(1+hue/2), 1.0)


# Path: opc/nphue.py
# @timefunc
# def h_to_rgb(h, sat=1, val=255.0):
#     # Local variation of hsv_to_rgb that only cares about a variable
#     # hue, with (s,v) assumed to be constant
#     # h should be a numpy array with values between 0.0 and 1.0
#     # hsv_to_rgb returns an array of uints between 0 and 255.
#     s = np.full_like(h, sat)
#     v = np.full_like(h, val)
#     hsv = np.dstack((h, s, v))
# 
#     return hsv_to_rgb(hsv)


# Path: art/plasma.py
from ._baseclass import ArtBaseClass
from opc.nphue import h_to_rgb
import numpy as np

class Art(ArtBaseClass):

    description = "Classic plasma (almost)"

    def __init__(self, matrix, config):
        ones = np.ones(matrix.numpix).reshape((matrix.height, matrix.width))
        self.x = ones*np.arange(matrix.width)
        self.y = np.flipud(np.rot90(np.rot90(ones)*np.arange(matrix.height)))

        self.base = 128000

    def start(self, matrix):
        pass

    def _dist(self, a, b, c, d):
        return np.sqrt((c-a)*(c-a)+(d-b)*(d-b))

    def refresh(self, matrix):

        xb = self.x + self.base
        yb = self.y + self.base

        c1 = self._dist(xb, self.y, 128.0, 128.0) / (matrix.smallest/2)
        c2 = self._dist(self.y, self.y, 64.0, 64.0) / (matrix.smallest/2)
        c3 = self._dist(self.x, yb / 7, 192.0, 64) / (matrix.smallest/2)
        c4 = self._dist(self.y, self.x, 192.0, 100.0) / (matrix.smallest/2)

        hue = np.sum(np.sin(c) for c in (c1, c2, c3, c4))
        hue = np.fmod(np.fabs(1+hue/2), 1.0)


        rgb = h_to_rgb(hue)