Пример #1
0
def explore_1d_automata(nb_frames):
    nb_simmetry = 4
    angle = 360 / nb_simmetry
    scale = angle / 90

    all_rules_config = list(itertools.product([0, 1], repeat=8))
    configs_idxs = np.random.choice(np.arange(len(all_rules_config)), 20)
    for idx in configs_idxs:
        print(scale)
        print("#####")
        print(f"Rule {idx}")
        config = all_rules_config[idx]
        print(config)
        rule = dict(
            zip(['111', '110', '101', '100', '011', '010', '001', '000'],
                config))
        animate_1d_automata(rule,
                            nb_frames=nb_frames,
                            scale=scale,
                            material_index=0)
        bpy.context.scene.frame_set(nb_frames)
        #random_camera_pos(np.random.randint(5, 200), np.random.randint(360), np.random.randint(360))
        random_gp_material()
        render_dir = Path.home() / "Downloads/automaton_1d/symm_4_colors"
        render(str(render_dir / f"rule_{idx}"), animation=False)
        render(str(render_dir / f"rule_{idx}"), animation=True)
Пример #2
0
def explore_hexagonal_automata(nb_frames: int, nb_runs: int, nb_rows: int,
                               nb_cols: int):
    render_dir = Path.home(
    ) / f"Downloads/automaton_hexagonal/flat_hexa_logo/{nb_frames}"
    render_dir.mkdir(exist_ok=True)
    with open(str(render_dir / "logs.txt"), 'w+') as f:
        for run in range(nb_runs):
            p_freeze = np.random.choice([1., 0.], 14)
            p_melt = np.random.choice([1., 0.], 14)
            print("#####")
            print(f"Run {run}")
            print(f"p_freeze {p_freeze}")
            print(f"p_melt {p_melt}")
            animate_hexagonal_automata(p_freeze,
                                       p_melt,
                                       nb_frames=nb_frames,
                                       nb_rows=nb_rows,
                                       nb_cols=nb_cols,
                                       material_index=0)
            bpy.context.scene.frame_set(nb_frames)
            #random_camera_pos(np.random.randint(5, 200), np.random.randint(360), np.random.randint(360))
            #andom_gp_material()

            render(str(render_dir / f"run_{run}"), animation=False)
            #render(str(render_dir / f"run_{run}"), animation=True)

            f.write(f"p_freeze:{p_freeze}-")
            f.write(f"p_melt:{p_melt}\n")
Пример #3
0
def single_run(automaton, nb_frames: int, render_path=None):
    nb_rows = automaton.shape[0]
    nb_cols = automaton.shape[1]

    cell_size = 0.6
    objs_verts = []
    for frame in range(0, nb_frames):
        if frame % 10 == 0:
            print("Automaton update - frame {}".format(frame))
        automaton.update()

        vertices = []
        negatives = []
        z = 0
        for row in range(nb_rows):
            for col in range(nb_cols):
                    x, y = calculate_hexagonal_cell_position(row, col, nb_rows, nb_cols, cell_size)

                    if automaton.grid[row, col]:
                        vertices.append((x, y, z))
                    else:
                        negatives.append((x, y, z))

        vertices = np.array(vertices)
        vertices += [0.0, 0.0, frame]
        objs_verts.append(vertices)

    anim_objs(objs_verts)
    return

    obj_name = 'snowflake'
    if obj_name not in bpy.context.scene.objects:
        create_object(vertices, edges=[], faces=[], obj_name=obj_name)
    else:
        obj = bpy.context.scene.objects[obj_name]
        mesh = obj.data
        bm = bmesh.new()

        # convert the current mesh to a bmesh (must be in edit mode)
        bpy.ops.object.mode_set(mode='EDIT')
        bm.from_mesh(mesh)
        bpy.ops.object.mode_set(mode='OBJECT')  # return to object mode

        for v in bm.verts:
            bm.verts.remove(v)
        for v in vertices:
            bm.verts.new(v)

        # make the bmesh the object's mesh
        bm.to_mesh(mesh)
        bm.free()  # always do this when finished

    if render_path:
        randomize_bsdf()
        render(render_path, animation=False)
Пример #4
0
def explore_hexagonal_automata(nb_frames):
    for run in range(40):
        p_freeze = np.random.choice([1., 0.], 14)
        p_melt = np.random.choice([1., 0.], 14)
        print("#####")
        print(f"Run {run}")
        print(f"p_freeze {p_freeze}")
        print(f"p_melt {p_melt}")
        animate_hexagonal_automata(p_freeze,
                                   p_melt,
                                   nb_frames=nb_frames,
                                   material_index=0)
        bpy.context.scene.frame_set(nb_frames)
        #random_camera_pos(np.random.randint(5, 200), np.random.randint(360), np.random.randint(360))
        random_gp_material()
        render_dir = Path.home() / "Downloads/automaton_hexagonal/flat_hexa"
        render(str(render_dir / f"run_{run}"), animation=False)
        render(str(render_dir / f"run_{run}"), animation=True)
Пример #5
0
def explore_hexagonal_automata(nb_frames: int, nb_runs: int, nb_rows: int,
                               nb_cols: int):
    render_dir = Path.home(
    ) / f"Documents/videos/cellular_automata/automaton_hexagonal/flat_hexa_good_extended"
    render_dir.mkdir(exist_ok=True)

    run = 0
    for i in range(5, 20):
        configs = load_good_configs(
            Path.home() /
            "Documents/videos/cellular_automata/automaton_hexagonal/flat_hexa_logo/{}"
            .format(i))
        for config in configs:
            p_freeze, p_melt = config

            automaton = HexagonalAutomaton(nb_rows=nb_rows,
                                           nb_cols=nb_cols,
                                           p_melt=p_melt,
                                           p_freeze=p_freeze)

            # Set middle cell as the only active one
            automaton.grid = np.zeros((nb_rows, nb_cols), dtype=np.uint8)
            automaton.grid[(nb_rows // 2, nb_cols // 2)] = 1

            animate_hexagonal_automata(p_freeze,
                                       p_melt,
                                       nb_frames=nb_frames,
                                       nb_rows=nb_rows,
                                       nb_cols=nb_cols,
                                       material_index=0)
            bpy.context.scene.frame_set(nb_frames)
            #random_camera_pos(np.random.randint(5, 200), np.random.randint(360), np.random.randint(360))
            #andom_gp_material()

            #render(str(render_dir / f"run_{run}"), animation=False)
            render(str(render_dir / f"run_{run}"), animation=True)
            run += 1
Пример #6
0
                # run and render
                for i in range(NUM_FRAMES):
                    try:
                        rf_system.run_simulation(config['steps'])
                    except ReactionDiffusionException as e:
                        print(f'System throw exception at frame {i}')
                        break
                    imgs.append(
                        cv2.normalize(rf_system.B,
                                      None,
                                      255,
                                      0,
                                      norm_type=cv2.NORM_MINMAX,
                                      dtype=cv2.CV_8U))
                    update_img(img_name, rf_system)
                    render(str(render_dir / f'still_f_{i:04}.png'))
                    bpy.context.scene.frame_set(i + 1)

                # write out config
                config['nb_frames'] = len(imgs)
                f.write(str(config) + '\n')

                # discard if too short
                if len(imgs) < min_frames:
                    continue

                # convert stills from imgs via ffmpeg
                ffmpeg_in = render_dir / f'still_f_%04d.png'
                ffmpeg_out = render_dir / f'run_{run}.mp4'
                subprocess.call(
                    f'ffmpeg -i "{ffmpeg_in}" -pix_fmt yuv420p -vframes {len(imgs)} "{ffmpeg_out}"',