Пример #1
0
 def test_get_transition_color_window(self):
     attributes = ['color1', 'color2', 'range', 'period', 'func', 'direction', 'trans_type', 'use_window']
     tests = [
         # [[[color1, color2, range, period, func, direction, trans_type, use_window]], step_number, window_size, result]
         [[[(255,0,0), (0,255,0), (0,10), 10, lambda x: 1 if x < 8 else 0, 1, 'base', True]], 1, 10, [(255,0,0),(255,0,0),(255,0,0),(0,255,0),(0,255,0),(0,255,0),(0,255,0),(0,255,0),(0,255,0),(0,255,0)]],
         [[[(255,0,0), (0,255,0), (0,10), 10, lambda x: 1 if x < 8 else 0, -1, 'base', True]], 1, 10, [(0,255,0),(0,255,0),(0,255,0),(0,255,0),(0,255,0),(0,255,0),(0,255,0),(255,0,0),(255,0,0),(255,0,0)]]
     ]
     # step across the tests
     for test in tests:
         # instantiate the Transition class
         t = trans.Transition()
         # step across the color functions
         for f in test[0]:
             cf = colorfunc.ColorFunc()
             # set color1
             cf.color1 = rgb.RGB()
             cf.color1.color = f[0]
             # set color2
             cf.color2 = rgb.RGB()
             cf.color2.color = f[1]
             # set the remaining attributes
             for a in range(2,len(attributes)):
                 setattr(cf, attributes[a], f[a])
             t.color_funcs.append(cf)
         # get the color window
         t.get_transition_window(test[1])
Пример #2
0
 def __init__(self):
     # initialize
     # color when func returns 0
     self.color1 = rgb.RGB()
     self.color1.base_color = (255, 0, 255)
     # initialize
     # color when func returns 1
     self.color2 = rgb.RGB()
     self.color2.base_color = (0, 0, 255)
     # intialize range
     # sets the range of values that may be used as input for the function property
     self.range = (0, 1)
     # initialize period
     # number of steps to use when traversing the range property
     self.period = 20
     # initialize the color function
     # func(i) => float, bounded (0,1)
     # func(i) which returns a float within range (0,1)
     # where i is a float bounded by the range property
     self.func = lambda i: math.sin(i * math.pi)
     # initialize direction
     # specifies scanning direction of the window wrt the function's graph
     # values can be -1 || 0 || 1 (left || no motion || right)
     self.direction = 1
     # initialize trans_type
     # specifies the type of color transition to use:
     # 'base' || 'white' || 'black'
     self.trans_type = 'base'
     # initialize use_window
     # True: use scanning winodw
     # False: set all LEDs the same color, same as window = 1
     self.use_window = True
Пример #3
0
 def test_cycle_setters(self):
     tests = [(220, 134, 45), (54, 0, 225), (0, 255, 0), (50, 40, 40),
              (40, 40, 40)]
     for t in tests:
         c1 = rgb.RGB()
         c1.color = t
         c2 = rgb.RGB()
         c2.base_color = c1.base_color
         c2.brightness = c1.brightness
         c2.white_level = c1.white_level
         self.assertEqual(c2.color, t)
Пример #4
0
 def test_init_happy(self):
     # instantiate RGB class
     color = rgb.RGB()
     # verify color
     self.assertEqual(color._color, rgb.WHITE_BASE)
     # verify order
     self.assertEqual(color._order, (0, 1, 2))
Пример #5
0
 def test_get_color_white_level(self):
     tests = [[(0, 0, 0), 0], [(10, 255, 50), 10 / 255]]
     # instantiate RGB class
     color = rgb.RGB()
     for t in range(len(tests)):
         result = color._get_color_white_level(tests[t][0])
         self.assertEqual(result, tests[t][1],
                          f"color: {tests[t][0]}, expected: {tests[t][1]}")
Пример #6
0
 def test_get_color_dominance_indices(self):
     tests = [[(1, 2, 3), (2, 1, 0)], [(3, 2, 1), (0, 1, 2)],
              [(3, 1, 2), (0, 2, 1)], [(1, 1, 1), (0, 1, 2)],
              [(1, 3, 1), (1, 0, 2)]]
     # instantiate RGB class
     color = rgb.RGB()
     for t in range(len(tests)):
         result = color._get_color_dominance_indices(tests[t][0])
         self.assertEqual(result, tests[t][1],
                          f"color: {tests[t][0]}, expected: {tests[t][1]}")
Пример #7
0
 def test_is_order_valid(self):
     tests = [[(0, 0, 0), False], [(0, 2, 1), True], [(2, 1, 0), True],
              [(7, 1, 0), False], [(7, 1, 0, 2), False], [(7, 1), False],
              [[0, 1, 2], False]]
     # instantiate RGB class
     color = rgb.RGB()
     for t in range(len(tests)):
         result = color._is_order_valid(tests[t][0])
         self.assertEqual(result, tests[t][1],
                          f"order: {tests[t][0]}, expected: {tests[t][1]}")
Пример #8
0
 def test_get_color(self):
     tests = [[(255, 75, 0), 0.5, 0.75, (127, 105, 95)]]
     # do tests
     # instantiate RGB class
     color = rgb.RGB()
     for t in range(len(tests)):
         result = color._get_color(tests[t][0], tests[t][1], tests[t][2])
         self.assertEqual(
             result, tests[t][3],
             f"color: {tests[t][0]}, base expected: {tests[t][3]} actual: {result}"
         )
Пример #9
0
    def test_get_base_color(self):
        tests = [[(255, 125, 75), (255, 70, 0)], [(255, 50, 0), (255, 50, 0)]]

        # instantiate RGB class
        color = rgb.RGB()
        for t in range(len(tests)):
            result = color._get_base_color(tests[t][0])
            self.assertEqual(
                result, tests[t][1],
                f"color: {tests[t][0]}, base expected: {tests[t][1]} actual: {result}"
            )
Пример #10
0
    def test_get_white_level_component(self):
        tests = [[(200, 157, 47), (0, 14, 47)], [(45, 45, 45), (45, 45, 45)]]

        # instantiate RGB class
        color = rgb.RGB()
        for t in range(len(tests)):
            result = color._get_white_level_component(tests[t][0])
            self.assertEqual(
                result, tests[t][1],
                f"color: {tests[t][0]}, white_level_component expected: {tests[t][1]} actual: {result}"
            )
Пример #11
0
 def test_get_color_transition_distance(self):
     # define tests
     tests = [
         [(255,0,0), (0,255,0), 0.5, 510, (255,255,0)],
         [(255,0,0), (0,255,0), 0, 510, (255,0,0)],
         [(255,0,0), (0,255,0), 1, 510, (0,255,0)],
         [(255,0,0), (0,255,0), 0.333, 510, (255,170,0)],
         [(255,0,0), (0,45,255), 0.75, 555, (94, 0, 255)]
     ]
     # do the test
     for test in tests:
         c1 = rgb.RGB()
         c1.color = test[0]
         c2 = rgb.RGB()
         c2.color = test[1]
         t = trans.Transition()
         dist = t._get_color_transition_distance(c1, c2, type='base')
         self.assertEqual(dist, test[3])
         result = t._get_color_transition_color(c1, c2, test[2]*dist, type='base')
         self.assertEqual(result.color, test[4])
Пример #12
0
 def test_cycle_methods(self):
     tests = [(220, 134, 45), (54, 0, 225), (50, 40, 40), (40, 40, 40)]
     color = rgb.RGB()
     for c in tests:
         result = c
         for _ in range(3):
             white_level = color._get_color_white_level(result)
             brightness = color._get_color_brightness(result)
             base_color = color._get_base_color(result)
             result = color._get_color(base_color, brightness, white_level)
         self.assertEqual(result, c,
                          f"color: {c}, expected: {c} actual: {result}")
Пример #13
0
    def test_get_brightness_component(self):
        tests = [[(200, 157, 47), (-55, -43, -13)], [(255, 50, 25), (0, 0, 0)],
                 [(3, 1, 1), (-252, -84, -84)], [(0, 0, 0), (0, 0, 0)]]

        # instantiate RGB class
        color = rgb.RGB()
        for t in range(len(tests)):
            result = color._get_brightness_component(tests[t][0])
            self.assertEqual(
                result, tests[t][1],
                f"color: {tests[t][0]}, brightness_component expected: {tests[t][1]} actual: {result}"
            )
Пример #14
0
 def test_get_brightness_modifier(self):
     tests = [[(255, 0, 0), 1, 0, (0, 0, 0)],
              [(255, 50, 0), 0, 0, (-255, -50, 0)]]
     # instantiate RGB class
     color = rgb.RGB()
     for t in range(len(tests)):
         result = color._get_brightness_modifier(tests[t][0], tests[t][1],
                                                 tests[t][2])
         self.assertEqual(
             result, tests[t][3],
             f"color: {tests[t][0]}, brightness: {tests[t][1]}, white_level_modifier: {tests[t][2]} expected: {tests[t][3]}"
         )
Пример #15
0
    def _get_base_transition(self, color1, color2, max_dist=rgb.MAX * 4):
        """Transitions from color1 to color2 using base color algorithm, use max_distance halt the transition before reaching color2

        Positional Arguments:
        color1 -- RGB object, starting color
        color2 -- RGB object, target color

        KW Arguments:
        max_dist -- int, maximum distance to travel during the transition
        """
        # track distance of transition
        dist = 0
        d = 0
        # create a new RGB inst to track transition color
        colorX = rgb.RGB(order=color1.order)
        colorX.color = color1.color
        # avoid backtracking across the same path
        if color1.dominance[1] != color2.dominance[0]:
            # color1[c1.d1] -> 0 => colorX
            colorX.base_color, d = self._set_component_value(
                colorX,
                color1.dominance[1],
                rgb.MIN,
                set_base=True,
                max_dist=max_dist - dist)
        dist += d
        # colorX[c2.d0] -> 255
        colorX.base_color, d = self._set_component_value(colorX,
                                                         color2.dominance[0],
                                                         rgb.MAX,
                                                         set_base=True,
                                                         max_dist=max_dist -
                                                         dist)
        dist += d
        # colorX[c2.d2] => 0
        colorX.base_color, d = self._set_component_value(colorX,
                                                         color2.dominance[2],
                                                         rgb.MIN,
                                                         set_base=True,
                                                         max_dist=max_dist -
                                                         dist)
        dist += d
        # colorX[c2.d1] -> color2[c2.d1]
        colorX.base_color, d = self._set_component_value(
            colorX,
            color2.dominance[1],
            color2.base_color[color2.dominance[1]],
            set_base=True,
            max_dist=max_dist - dist)
        dist += d
        # return new color and dist
        return colorX, dist
Пример #16
0
 def test_get_white_level_modifier(self):
     tests = [[(255, 0, 0), 1, (0, 255, 255)],
              [(255, 0, 0), 3, (0, 255, 255)], [(0, 255, 125), 0,
                                                (0, 0, 0)],
              [(0, 255, 125), -1, (0, 0, 0)]]
     # instantiate RGB class
     color = rgb.RGB()
     for t in range(len(tests)):
         result = color._get_white_level_modifier(tests[t][0], tests[t][1])
         self.assertEqual(
             result, tests[t][2],
             f"color: {tests[t][0]}, white_level: {tests[t][1]} expected: {tests[t][2]}"
         )
Пример #17
0
 def test_is_base_color(self):
     tests = [[(0, 0, 0), False], [(255, 255, 75), False],
              [(255, 100, 255), False], [(20, 255, 255), False],
              [(255, 255, 255), False], [(255, 0, 0), True],
              [(0, 255, 0), True], [(0, 0, 255), True], [(255, 255, 0),
                                                         True],
              [(255, 0, 255), True], [(0, 255, 255), True],
              [(255, 100, 0), True], [(100, 255, 0), True],
              [(255, 0, 100), True], [(100, 0, 255), True],
              [(0, 255, 100), True], [(0, 100, 255), True],
              [(0, 100, 255, 0), False], [(0, 100), False]]
     # instantiate RGB class
     color = rgb.RGB()
     for t in range(len(tests)):
         result = color._is_base_color(tests[t][0])
         self.assertEqual(result, tests[t][1],
                          f"color: {tests[t][0]}, expected: {tests[t][1]}")
Пример #18
0
 def test_base_color_setter_exception(self):
     # instantiate RGB class
     color = rgb.RGB()
     # should raise
     with self.assertRaises(ValueError):
         color.base_color = ()
Пример #19
0
 def __init__(self):
     self.led = rgb.RGB()
     self.led.setup()
Пример #20
0
import display

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

R = 22
G = 23
B = 24

LCD_CS = 2
LCD_RST = 3
LCD_A0 = 4
LCD_CLK = 27
LCD_SI = 17

leds = rgb.RGB(R, G, B)
leds.set_color(*rgb.ILARIA)

d = display.RGBDisplay(2, 3, 4, 27, 17)

d.lcd_ascii168_string(2, 2, "RIGA 1")
d.lcd_ascii168_string(2, 4, "RIGA 2")
d.lcd_ascii168_string(2, 6, "RIGA 3")

time.sleep(20)

# for f in (rfade, gfade, bfade):
#     for x in xrange(100):
#         i = x / 100.0
#         f.ChangeDutyCycle(100.0 * i)
#         time.sleep(0.1)
Пример #21
0
 def test_get_white_level_modifier_invalid_color(self):
     # instantiate RGB class
     color = rgb.RGB()
     # should raise
     with self.assertRaises(ValueError):
         color._get_white_level_modifier([], 1)
Пример #22
0
 def test_get_brightness_modifier_color(self):
     # instantiate RGB class
     color = rgb.RGB()
     # should raise
     with self.assertRaises(ValueError):
         color._get_brightness_modifier((1, 2, 3), 1, (-5000, 6, 7))
Пример #23
0
import rgb
from time import sleep
import pulseio
import board

r = pulseio.PWMOut(board.A2)
g = pulseio.PWMOut(board.A3)
b = pulseio.PWMOut(board.A4)
regrbl = rgb.RGB(r,g,b)

print("red")
regrbl.red()
sleep(2)
print("yellow")
regrbl.yellow()
sleep(2)
print("green")
regrbl.green()
sleep(2)
print("cyan")
regrbl.cyan()
sleep(2)
print("blue")
regrbl.blue()
sleep(2)
print("magenta")
regrbl.magenta()
sleep(2)
print("white")
regrbl.white()
sleep(2)
Пример #24
0
 def test_order_setter(self):
     order = (1, 2, 0)
     c = rgb.RGB()
     self.assertNotEqual(order, c.order)
     c.order = order
     self.assertEqual(order, c.order)
Пример #25
0
 def test_dominance_getter(self):
     # instantiate RGB class
     color = rgb.RGB()
     color.color = (2, 1, 3)
     self.assertEqual(color.dominance, (2, 0, 1))