def make_static_dyno(gif_name,
                     dyno=DynoBit(),
                     static_color_list=None,
                     save_dyno=True):
    frame_count = 10
    temp_file_names = make_temp_file_names(frame_count, "temp_static")
    background_color_index_list = dyno.get_background_index_list()
    dyno_pixels = dyno.pixels()

    # Change backgroud color based on activity if not supplied
    if static_color_list == None:
        if dyno.activity == "Diurnal":
            static_color_list = dc.COLOR_LIST_LIGHT_GREYS
        if dyno.activity == "Nocturnal":
            static_color_list = dc.COLOR_LIST_DARK_GREYS

    # Apply power and write temp dyno images
    for file in temp_file_names:
        for i in background_color_index_list:
            dyno_pixels[i] = choice(static_color_list)

        dyno.save_dyno_image(dyno_pixels, file)

    if save_dyno:
        save_dyno_gif(gif_name, temp_file_names, bounce=False, fps=25)

    remove_temp_files(temp_file_names)
Esempio n. 2
0
def make_eye_roll_dyno(gif_name, dyno=DynoBit()):
    frame_count = 4  # Because the eye is made of 4 bits (a nibble!)
    old_index_list = [(7, 17), (6, 17), (6, 16), (7, 16)]
    new_index_list = old_index_list[1:] + [old_index_list[0]]

    temp_file_names = make_temp_file_names(frame_count, "temp_eye_roll")

    if not frame_count == len(old_index_list) == len(new_index_list) == len(
            temp_file_names):
        raise ValueError(
            f"frame_count inconsistent: {frame_count} {len(old_index_list)} {len(new_index_list)} {len(temp_file_names)}"
        )

    new_pixels = dyno.pixels()
    old_pixels = dyno.pixels()
    for file in temp_file_names:
        dyno.save_dyno_image(pixel_array=new_pixels, imgname=file)
        for i in range(frame_count):  # Move pupil one position
            new_pixels[new_index_list[i]] = old_pixels[old_index_list[i]]
        old_pixels = np.copy(new_pixels)

    save_dyno_gif(gif_name,
                  temp_file_names + [temp_file_names[0]],
                  bounce=True,
                  fps=8)

    remove_temp_files(temp_file_names)
def make_evolving_dyno(gif_name, from_dyno=None, to_dyno=None, frame_count=10):
    if from_dyno is None and to_dyno is None:
        from_dyno = DynoBit()
        from_dyno.randomize()
        to_dyno = DynoBit()
        to_dyno.randomize()
    if from_dyno != None and to_dyno is None:
        to_dyno = copy.copy(from_dyno)
    if from_dyno is None and to_dyno != None:
        from_dyno = copy.copy(to_dyno)

    if from_dyno.ROWS is not to_dyno.ROWS or from_dyno.COLUMNS is not to_dyno.COLUMNS:
        raise ValueError(
            f"from_dyno dimensions != to_dyno dimensions: {(from_dyno.ROWS, from_dyno.COLUMNS)} - {(to_dyno.ROWS, to_dyno.COLUMNS)}"
        )

    # Set species for evolution: Euoplocephalus & T-Rex evolve into Euoplorex
    if from_dyno.species == "Euoplocephalus" or from_dyno.species == "T-Rex":
        setattr(to_dyno, "species", "Euoplorex")
    elif to_dyno.species == "Euoplocephalus" or to_dyno.species == "T-Rex":
        setattr(from_dyno, "species", "Euoplorex")
    else:
        setattr(from_dyno, "species", "Euoplocephalus")

    # Make ROWSxCOLUMS list of list containing interval color of each pixel
    dyno_pixels_intervals = []
    from_dyno_pixels = from_dyno.pixels()
    to_dyno_pixels = to_dyno.pixels()
    for r in range(to_dyno.ROWS):
        for c in range(to_dyno.COLUMNS):
            from_dyno_pixels
            dyno_pixels_intervals += [
                dc.interval(from_dyno_pixels[r, c], to_dyno_pixels[r, c],
                            frame_count)
            ]

    # Use list of intervals to make each dyno frame
    temp_file_names = make_temp_file_names(frame_count, "temp_evolving")
    for i in range(frame_count):
        new_dyno_pixels = np.array([[(0, 0, 0)] * to_dyno.ROWS] *
                                   to_dyno.COLUMNS,
                                   dtype=np.uint8)

        i_dpi = 0
        for r in range(to_dyno.ROWS):
            for c in range(to_dyno.COLUMNS):
                new_dyno_pixels[r, c] = tuple(dyno_pixels_intervals[i_dpi][i])
                i_dpi += 1

        from_dyno.save_dyno_image(new_dyno_pixels, imgname=temp_file_names[i])

    save_dyno_gif(gif_name,
                  temp_file_names + [temp_file_names[-1]],
                  bounce=True)

    remove_temp_files(temp_file_names)
def make_disco_dyno(gif_name,
                    dyno=DynoBit(),
                    disco_attr_name="background_color",
                    disco_color_list=dc.RAINBOW):
    temp_file_names = make_temp_file_names(len(disco_color_list), "temp_disco")

    for i in range(len(disco_color_list)):
        setattr(dyno, disco_attr_name, disco_color_list[i])
        dyno.save_dyno_image(imgname=temp_file_names[i])

    save_dyno_gif(gif_name, temp_file_names, bounce=False)

    remove_temp_files(temp_file_names)
Esempio n. 5
0
def make_laser_dyno(gif_name, dyno=DynoBit(), laser_color=dc.RED):
    laser_index_list = [(7, 17), (8, 18), (9, 19), (10, 20), (11, 21),
                        (12, 22), (13, 23)]
    temp_file_names = make_temp_file_names(
        len(laser_index_list) + 1, "temp_laser")
    pixels = dyno.pixels()

    dyno.save_dyno_image(imgname=temp_file_names[0])
    for i in range(len(laser_index_list)):
        pixels[laser_index_list[i]] = laser_color
        dyno.save_dyno_image(pixel_array=pixels,
                             imgname=temp_file_names[i + 1])

    save_dyno_gif(gif_name, temp_file_names, bounce=True)

    remove_temp_files(temp_file_names)
Esempio n. 6
0
def make_smoking_dyno(gif_name, dyno=DynoBit()):
    frame_count = 10
    temp_file_names = make_temp_file_names(frame_count, "temp_smoking")
    base_pixels = dyno.pixels()

    # Bloodshot eyes
    base_pixels[[6, 6, 7], [17, 16, 16]] = dc.BLOOD
    base_pixels[7, 17] = dc.BLACK

    # Blunt
    curr_frame = 0
    base_pixels[12, [20, 21, 22]] = dc.BRICK
    base_pixels[12, 22] = dc.RED
    dyno.save_dyno_image(pixel_array=base_pixels,
                         imgname=temp_file_names[curr_frame])

    # Smoke
    curr_frame = 1
    working_dyno = copy.copy(base_pixels)
    working_dyno[12, 22] = dc.darker(dc.RED, 0.1)
    working_dyno[11, 22] = dc.SMOKE
    dyno.save_dyno_image(working_dyno, temp_file_names[curr_frame])

    curr_frame = 2
    working_dyno = copy.copy(base_pixels)
    working_dyno[12, 22] = dc.darker(dc.RED, 0.1)
    working_dyno[[11, 10], [22, 22]] = dc.SMOKE
    dyno.save_dyno_image(working_dyno, temp_file_names[curr_frame])

    curr_frame = 3
    working_dyno = copy.copy(base_pixels)
    working_dyno[[11, 10, 9], [22, 22, 21]] = dc.SMOKE
    dyno.save_dyno_image(working_dyno, temp_file_names[curr_frame])

    curr_frame = 4
    working_dyno = copy.copy(base_pixels)
    working_dyno[[11, 10, 8, 9], [22, 22, 21, 22]] = dc.SMOKE
    dyno.save_dyno_image(working_dyno, temp_file_names[curr_frame])

    curr_frame = 5
    working_dyno = copy.copy(base_pixels)
    working_dyno[12, 22] = dc.darker(dc.RED, 0.1)
    working_dyno[[11, 10, 7, 8, 9], [22, 22, 21, 22, 21]] = dc.SMOKE
    dyno.save_dyno_image(working_dyno, temp_file_names[curr_frame])

    curr_frame = 6
    working_dyno = copy.copy(base_pixels)
    working_dyno[12, 22] = dc.darker(dc.RED, 0.1)
    working_dyno[[11, 10, 6, 7, 8, 9], [22, 22, 20, 22, 21, 22]] = dc.SMOKE
    dyno.save_dyno_image(working_dyno, temp_file_names[curr_frame])

    curr_frame = 7
    working_dyno = copy.copy(base_pixels)
    working_dyno[[11, 10, 5, 6, 7, 8, 9],
                 [22, 22, 20, 21, 21, 22, 21]] = dc.SMOKE
    dyno.save_dyno_image(working_dyno, temp_file_names[curr_frame])

    curr_frame = 8
    working_dyno = copy.copy(base_pixels)
    working_dyno[[11, 10, 4, 5, 6, 5, 7, 8, 9],
                 [22, 22, 19, 20, 21, 22, 22, 21, 22]] = dc.SMOKE
    dyno.save_dyno_image(working_dyno, temp_file_names[curr_frame])

    curr_frame = 9
    working_dyno = copy.copy(base_pixels)
    working_dyno[12, 22] = dc.darker(dc.RED, 0.1)
    working_dyno[[11, 10, 3, 4, 5, 4, 6, 7, 8, 9],
                 [22, 22, 19, 19, 20, 22, 21, 21, 22, 21]] = dc.SMOKE
    dyno.save_dyno_image(working_dyno, temp_file_names[curr_frame])

    save_dyno_gif(gif_name, [temp_file_names[0]] + temp_file_names,
                  bounce=False,
                  fps=5)

    remove_temp_files(temp_file_names)