Ejemplo n.º 1
0
    def testChooseSimple(self):
        # select a single value from a list of values.
        options = [
            [0, 1, 2],
            [3, 4, 5],
            [6, 7, 8]
        ]

        for i in range(len(options)):
            self.assertEqual(choose(i, *options), options[i])
Ejemplo n.º 2
0
def hsb_to_rgb(h, s, v, *rest):
    i = floor(6 * h)
    f = 6 * h - i
    i = mod(i, 6)
    p = v * (1 - s)
    q = v * (1 - f * s)
    t = v * (1 - (1 - f) * s)

    r, g, b = choose(i, (v, t, p), (q, v, p), (p, v, t), (p, q, v), (t, p, v),
                     (v, p, q))

    return (r, g, b) + rest
Ejemplo n.º 3
0
def hsb_to_rgb(h, s, v, *rest):
    i = floor(6 * h)
    f = 6 * h - i
    i = mod(i, 6)
    p = v * (1 - s)
    q = v * (1 - f * s)
    t = v * (1 - (1 - f) * s)

    r, g, b = choose(i,
        (v, t, p),
        (q, v, p),
        (p, v, t),
        (p, q, v),
        (t, p, v),
        (v, p, q))

    return (r, g, b) + rest
Ejemplo n.º 4
0
    def testChooseComplex(self):
        def m(i):
            return [[10 * i + 0, 10 * i + 1],
                    [10 * i + 2, 10 * i + 3]]

        selector = [[0, 1],
                    [1, 2]]

        a = choose(selector,
                    (m(1), m(2), m(3)),
                    (m(4), m(5), m(6)),
                    (m(7), m(8), m(9)))

        # choose() operates on column after column of the options matrix, i.e.
        # in the example above, the selector is first applied to (m(1), m(4), m(7)),
        # then to (m(2), m(5), m(8)), and so on. let's calculate the result for the
        # first column:

        # selector (integers indicate from which option to take a value):
        # [0 1]
        # [1 2]

        # option #0 / column 1 (i.e. m(1)):
        # [10 11]
        # [12 13]

        # option #1 / column 1 (i.e. m(4)):
        # [40 41]
        # [42 43]

        # option #2 / column 1 (i.e. m(7)):
        # [70 71]
        # [72 73]

        # choose() now picks the right value from each options depending on selector:

        # [10 41]
        # [42 73]

        self.assertEqual(len(a), 3)
        self.assertEqualArrays(a[0], [[10, 41], [42, 73]])
        self.assertEqualArrays(a[1], [[20, 51], [52, 83]])
        self.assertEqualArrays(a[2], [[30, 61], [62, 93]])