Esempio n. 1
0
    def make_part(self):
        length = random.randrange(0, self.state.top - self.state.bottom) + 5
        if random.randrange(0, 100) < 50:
            for _ in range(length):
                yield Color(0, 0, 0, 3500)
            return

        brightness = 0
        increment = 0.6 / length

        if not self.blank_lines:
            hue_range = random.choice(self.hue_ranges)

        for i in range(length):
            if self.blank_lines:
                hue = 0
                brightness = 0
            else:
                hue = hue_range.make_hue()

            tip = False
            if i == length - 1 and self.line_tip_hue is not None:
                hue = self.line_tip_hue.make_hue()
                brightness = 0.8
                tip = True

            color = Color(hue, 1, brightness, 3500)
            color.tip = tip
            yield color

            brightness += increment
Esempio n. 2
0
 def make_color(self, hue):
     if hue is White:
         return Color(0, 0, 1, 4500)
     elif hue is Black:
         return Color(0, 0, 0, 3500)
     else:
         return Color(hue, 1, 1, 3500)
Esempio n. 3
0
 def place_random(self, amount):
     for _ in range(amount):
         ch = random.choice(characters)
         left, top = self.random_coord()
         color = Color(random.randrange(0, 360), 1, 1, 3500)
         self.canvas.set_all_points_for_tile(left, top, ch.width, ch.height,
                                             ch.get_color_func(color))
Esempio n. 4
0
async def tile_dice(target, serials, afr, **kwargs):
    canvas = Canvas()

    def default_color_func(i, j):
        if j == -3:
            return Color(0, 1, 0.4, 3500)
        return Color(0, 0, 0, 3500)

    canvas.set_default_color_func(default_color_func)

    numbers = ["1", "2", "3", "4", "5"]
    characters = [dice[n] for n in numbers]
    color = Color(100, 1, 1, 3500)
    put_characters_on_canvas(canvas, characters, coords_for_horizontal_line, color)

    orientations = {}
    async for pkt, _, _ in target.script(TileMessages.GetDeviceChain()).run_with(
        serials, afr, **kwargs
    ):
        if pkt | TileMessages.StateDeviceChain:
            orientations[pkt.serial] = orientations_from(pkt)

    made, _ = make_rgb_and_color_pixels(canvas, 5)

    msgs = []
    for serial in serials:
        os = orientations.get(serial)
        for msg in canvas_to_msgs(
            canvas, coords_for_horizontal_line, duration=1, acks=True, orientations=os
        ):
            msg.target = serial
            msgs.append(msg)

    await target.script(msgs).run_with_all(None, afr, **kwargs)
    return made
Esempio n. 5
0
class NyanCharacter(Character):
    colors = {
        "c": Color(207, 0.47, 0.14, 3500),  # cyan
        "y": Color(60, 1, 0.11, 3500),  # yellow
        "w": Color(0, 0, 0.3, 3500),  # white
        "p": Color(345, 0.25, 0.12, 3500),  # pink
        "o": Color(24, 1, 0.07, 3500),  # orange
        "r": Color(0, 1, 0.15, 3500),  # red
        "b": Color(240, 1, 0.15, 3500),  # blue
        "g": Color(110, 1, 0.15, 3500),  # green
    }
Esempio n. 6
0
    def __init__(self, coords):
        self.color = Color(random.randrange(0, 360), 1, 1, 3500)

        self.wait = 0
        self.filled = {}
        self.remaining = {}

        for (left, top), (width, height) in coords:
            for i in range(left, left + width):
                for j in range(top, top - height, -1):
                    self.remaining[(i, j)] = True
Esempio n. 7
0
    def make_canvas(self, state, coords):
        canvas = Canvas()
        filled, _, wait = state

        color = self.color
        if wait > 1:
            color = Color(0, 0, 0, 3500)

        for point in filled:
            canvas[point] = color

        return canvas
Esempio n. 8
0
    def place_random(self, amount):
        for _ in range(amount):
            if self.options.palette:
                hue, saturation, brightness, kelvin = random.choice(self.options.palette)
            else:
                hue = random.randrange(0, 360)
                saturation = random.randrange(5, 10) / 10
                brightness = random.randrange(1, 10) / 10
                kelvin = random.randrange(2500, 9000)

            point = self.random_coord()
            if point not in self.twinkles:
                self.directions[point] = 1 if brightness < 0.6 else 0
                self.twinkles[point] = Color(hue, saturation, brightness, kelvin)
Esempio n. 9
0
    def pixels(self):
        j = self.bottom + sum(len(p) for p in self.parts)
        for part in self.parts:
            info = {"hues": []}
            for hue in part:
                j -= 1
                if hue is not None:
                    if "position" not in info:
                        info["position"] = j
                    info["hues"].insert(0, hue)

            hues = info["hues"]
            if not hues:
                continue

            position = info["position"]

            if len(hues) == 1:
                hue = hues[0]
                brightness = clamp(1.0 - (position - math.floor(position)))
                color = Color(hue, 1, brightness, 3500)
                yield (self.column, math.floor(position)), color

            else:
                closeness = clamp(1.0 - (position - math.floor(position)))
                head_color = Color(hues[0], 1, closeness, 3500)
                middle_hue = hues[0] + min(
                    [10, (hues[2] - hues[0]) * closeness])
                if middle_hue > 360:
                    middle_hue -= 360

                middle_color = Color(middle_hue, 1, 1, 3500)
                body_color = Color(hues[2], 1, 1, 3500)

                for i, color in enumerate(
                    (head_color, middle_color, body_color)):
                    yield (self.column, math.floor(position) + i), color
Esempio n. 10
0
    def make_canvas(self, state, coords):
        """
        This is called for each tile set every time we want to refresh the state
        photons handles turning the points on the canvas into light on the tiles
        """
        canvas = Canvas()

        color = state.color
        if state.wait > 1:
            color = Color(0, 0, 0, 3500)

        for point in state.filled:
            canvas[point] = color

        return canvas
Esempio n. 11
0
 def make_canvas(self):
     canvas = Canvas()
     for (left, top), (width, height) in self.coords:
         for i in range(left, left + width):
             line = self.lines[i]
             for j in range(top - height, top):
                 got = line[j]
                 if self.options.blinking_pixels:
                     if not getattr(got, "tip",
                                    False) and random.randrange(0, 100) < 5:
                         got = Color(got.hue, got.saturation,
                                     got.brightness, got.kelvin)
                         got.brightness = 0
                 canvas[(i, j)] = got
     return canvas
Esempio n. 12
0
class NyanCharacter(Character):
    colors = {
        'c': Color(207, 0.47, 0.14, 3500)  # cyan
        ,
        'y': Color(60, 1, 0.11, 3500)  # yellow
        ,
        'w': Color(0, 0, 0.3, 3500)  # white
        ,
        'p': Color(345, 0.25, 0.12, 3500)  # pink
        ,
        'o': Color(24, 1, 0.07, 3500)  # orange
        ,
        'r': Color(0, 1, 0.15, 3500)  # red
        ,
        'b': Color(240, 1, 0.15, 3500)  # blue
        ,
        'g': Color(110, 1, 0.15, 3500)  # green
    }
Esempio n. 13
0
 def default_color_func(i, j):
     if j == -3:
         return Color(0, 1, 0.4, 3500)
     return Color(0, 0, 0, 3500)
Esempio n. 14
0
 def make_new_color(self, surrounding):
     if self.new_color_style == "random":
         return Color(random.randrange(0, 360), 1, 1, 3500)
     else:
         return Color.average(surrounding)
Esempio n. 15
0
 def color(self):
     return Color(self.hue, self.saturation, self.brightness,
                  self.kelvin)
Esempio n. 16
0
 def default_color_func(i, j):
     return canvas.get((i, j), dflt=Color(0, 0, 0, 3500))
Esempio n. 17
0
 def dcf(i, j):
     return Color(0, 0, 0, 3500)
Esempio n. 18
0
 def get_color(x, y):
     color = rows[y][x]
     return Color(color.hue, color.saturation, color.brightness,
                  color.kelvin)
Esempio n. 19
0
 def setup(self):
     self.color = Color(random.randrange(0, 360), 1, 1, 3500)