# 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
from random import random
from math import fabs, sqrt

    def _reset(self, matrix):
        self.color = random()
        self.y = matrix.height - 1 - self.radius
        self.dy = -1.3

    def refresh(self, matrix):
        matrix.shift(ds=0.75, dv=0.9)

        self.x = self.x + self.dx*self.dt
        self.y = self.y + self.dy*self.dt

        absdx, absdy = fabs(self.dx), fabs(self.dy)

        if self.x < self.radius:
            self.dx = absdx
        elif self.x >= (matrix.width-self.radius-1):
            self.dx = -absdx

        if self.y < self.radius:
            self.dy = absdy
        elif self.dy < 0.2 and self.dy > 0:
            self.dy = -absdy

        self.dy = self.dy - self.accel*self.dt

        if self.dy < 0 and self.y < self.radius:
            self._reset(matrix)
        else:
            matrix.fillCircle(self.x, self.y, self.radius,

# 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/ball.py
from ._baseclass import ArtBaseClass
from opc.hue import hsvToRgb
from random import random
from math import fabs, sqrt


    def _reset(self, matrix):
        self.color = random()
        self.y = matrix.height - 1 - self.radius
        self.dy = -1.3

    def refresh(self, matrix):
        matrix.shift(ds=0.75, dv=0.9)

        self.x = self.x + self.dx*self.dt
        self.y = self.y + self.dy*self.dt

        absdx, absdy = fabs(self.dx), fabs(self.dy)

        if self.x < self.radius:
            self.dx = absdx
        elif self.x >= (matrix.width-self.radius-1):
            self.dx = -absdx

        if self.y < self.radius:
            self.dy = absdy
        elif self.dy < 0.2 and self.dy > 0:
            self.dy = -absdy

        self.dy = self.dy - self.accel*self.dt

        if self.dy < 0 and self.y < self.radius:
            self._reset(matrix)
        else:
            matrix.fillCircle(self.x, self.y, self.radius,

                              hsvToRgb(self.color))