# Path: opc/matrix/hq.py
# class HQ(object):
# 
#     """
#     use the HQ class to savely wrap art init blocks when you need to
#     switch on HQ for set-up purposes. For example:
# 
#         from opc.matrix import HQ
# 
# 
#         class Art(object):
# 
#             def __init__(self, matrix):
# 
#                 with HQ(matrix):
#                     initialization stuff...
#     """
# 
#     def __init__(self, matrix):
#         self.matrix = matrix
# 
#     def __enter__(self):
#         self.matrix.hq()
# 
#     def __exit__(self, type, value, traceback):
#         self.matrix.hq(False)


from ._baseclass import ArtBaseClass
from opc.matrix import HQ
from random import random
import numpy as np



class Channel(object):

    def __init__(self, matrix):
        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.delta = random()*0.5+0.2 

    def refresh(self, matrix):
        self.x += self.delta
        self.y += self.delta

        c1 = self.x/16
        c2 = self.y/8
        c3 = (self.x+self.y)/16
        c4 = np.sqrt((self.x*self.x)+(self.y*self.y))/8

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


class Art(ArtBaseClass):

    description = "Plasma by RGB channel"

    def __init__(self, matrix, config):

# Path: opc/matrix/hq.py
# class HQ(object):
# 
#     """
#     use the HQ class to savely wrap art init blocks when you need to
#     switch on HQ for set-up purposes. For example:
# 
#         from opc.matrix import HQ
# 
# 
#         class Art(object):
# 
#             def __init__(self, matrix):
# 
#                 with HQ(matrix):
#                     initialization stuff...
#     """
# 
#     def __init__(self, matrix):
#         self.matrix = matrix
# 
#     def __enter__(self):
#         self.matrix.hq()
# 
#     def __exit__(self, type, value, traceback):
#         self.matrix.hq(False)


# Path: art/rgbplasma.py
from ._baseclass import ArtBaseClass
from opc.matrix import HQ
from random import random
import numpy as np




class Channel(object):

    def __init__(self, matrix):
        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.delta = random()*0.5+0.2 

    def refresh(self, matrix):
        self.x += self.delta
        self.y += self.delta

        c1 = self.x/16
        c2 = self.y/8
        c3 = (self.x+self.y)/16
        c4 = np.sqrt((self.x*self.x)+(self.y*self.y))/8

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


class Art(ArtBaseClass):

    description = "Plasma by RGB channel"

    def __init__(self, matrix, config):

        with HQ(matrix):