Exemplo n.º 1
0
def other_draw(describe, values):
    if describe:
        return "Animate this"
    
    from dummylog import DummyLog
    print("Finding ranges...")
    ranges = calc(DummyLog(), values, 2, draw={"mode": "calc"})
    print("Drawing frames...")
    calc(DummyLog(), values, 2, draw=ranges)

    import subprocess
    import os
    cmd = [
        "ffmpeg", "-y",
        "-hide_banner",
        "-f", "image2",
        "-framerate", "1", 
        "-i", "frame_%05d.png", 
        "-c:v", "libx264", 
        "-profile:v", "main", 
        "-pix_fmt", "yuv420p", 
        "-vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2",
        "-an", 
        "-movflags", "+faststart",
        os.path.join("animations", "animation_%02d.mp4" % (get_desc()[0],)),
    ]
    print("$ " + " ".join(cmd))
    subprocess.check_call(cmd)
Exemplo n.º 2
0
def other_animate(describe, values):
    if describe:
        return "Animate frames"

    from dummylog import DummyLog
    calc(DummyLog(), values, True, animate=True)
    print("Done, created animation...")
Exemplo n.º 3
0
def draw_internal(values, draw_type, file_extra):
    from dummylog import DummyLog
    print("First pass")
    width, height = calc(DummyLog(), values, 2, draw={"mode": "size"})
    print("Draw pass")
    calc(DummyLog(),
         values,
         2,
         draw={
             "mode": "draw",
             "width": width,
             "height": height,
             "type": draw_type,
         })

    import subprocess
    import os
    cmd = [
        "ffmpeg",
        "-y",
        "-hide_banner",
        "-f",
        "image2",
        "-framerate",
        "10",
        "-i",
        "frame_%05d.png",
        "-c:v",
        "libx264",
        "-profile:v",
        "main",
        "-pix_fmt",
        "yuv420p",
        "-vf",
        "pad=ceil(iw/2)*2:ceil(ih/2)*2",
        "-an",
        "-movflags",
        "+faststart",
        os.path.join("animations",
                     "animation_%02d%s.mp4" % (get_desc()[0], file_extra)),
    ]
    print("$ " + " ".join(cmd))
    subprocess.check_call(cmd)
Exemplo n.º 4
0
def other_animate(describe, values):
    if describe:
        return "Animate frames"

    from grid import Grid
    from dummylog import DummyLog
    calc(DummyLog(), values, 2, animate=True)
    Grid.make_animation(output_name="animation_%02d" % (get_desc()[0], ),
                        file_format="mp4")
    print("Done, created animation...")
Exemplo n.º 5
0
def other_sample(describe, values):
    if describe:
        return "Produce a sample output"

    from dummylog import DummyLog
    log = DummyLog()
    values = log.decode_values("""
        .#.
        ..#
        ###
    """)
    log("---- Part 1 ----")
    xr, yr = calc(log, values, 1, sample=(1,), max_count=2)
    calc(log, values, 1, sample=(2, xr, yr), max_count=2)

    log("")
    log("---- Part 2 ----")
    xr, yr = calc(log, values, 2, sample=(1,), max_count=2)
    calc(log, values, 2, sample=(2, xr, yr), max_count=2)
Exemplo n.º 6
0
def other_save_state(describe, values):
    if describe:
        return "Save the state from part 2"
    else:
        from dummylog import DummyLog
        import os
        fn = os.path.join("Puzzles", "day_14_state.txt")
        log = DummyLog(fn)
        calc(log, values, 2, save_state=True)
        print("Done, created " + fn)
Exemplo n.º 7
0
def other_draw(describe, values):
    if describe:
        return "Animate this"
    
    from dummylog import DummyLog
    disp, fixup, steps = calc(DummyLog(), values, 2, draw=1)

    for cur in steps:
        for x, y, _ in fixup[cur]:
            disp[x, y] = "*"

    import random
    w, h = disp.get_font_size(13)
    index = 0

    for cur in steps:
        index += 1
        print(f"{index:2d} / {len(steps):2d}: {cur}")
        reveal = list(range(len(fixup[cur])))
        random.shuffle(reveal)
        revealed = set()
        for to_reveal in reveal:
            revealed.add(to_reveal)
            for _ in range(2):
                i = 0
                for x, y, digit in fixup[cur]:
                    color = (0, 0, 0)
                    if i not in revealed:
                        digit = chr(random.randint(33, 125))
                        color = (32, 32, 32)
                    disp[x, y] = [digit, color]
                    i += 1
                disp.draw_grid(show_lines=False, default_color=(0,0,0), font_size=13, cell_size=(w,h), color_map={})

    for y in disp.y_range():
        print("".join([x if isinstance(x, str) else x[0] for x in [disp[x, y] for x in disp.x_range()]]))

    import subprocess
    import os
    cmd = [
        "ffmpeg", "-y",
        "-hide_banner",
        "-f", "image2",
        "-framerate", "30", 
        "-i", "frame_%05d.png", 
        "-c:v", "libx264", 
        "-profile:v", "main", 
        "-pix_fmt", "yuv420p", 
        "-vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2",
        "-an", 
        "-movflags", "+faststart",
        os.path.join("animations", "animation_%02d.mp4" % (get_desc()[0],)),
    ]
    print("$ " + " ".join(cmd))
    subprocess.check_call(cmd)
Exemplo n.º 8
0
def main(lines):
    sys.path.insert(0, os.path.join('..', '..', 'Helpers'))

    from program import Program
    from dummylog import DummyLog

    #Program.debug(lines)
    p = Program([int(x) for x in lines.split(",")], DummyLog())
    while p.flag_running:
        p.tick()
        while len(p.output) > 0:
            sys.stdout.write(chr(p.get_output()))
            sys.stdout.flush()
Exemplo n.º 9
0
def draw_internal(values, draw_type, file_extra):
    import os
    from dummylog import DummyLog

    for cur in os.listdir('.'):
        if cur.startswith("frame_") and cur.endswith(".png"):
            os.unlink(cur)

    print("First pass")
    size = calc(DummyLog(), values, 2, draw={
        "mode": "size",
        "skip": 0,
    })
    print("Draw pass")
    calc(DummyLog(), values, 2, draw={
        "mode": "draw", 
        "size": size,
        "type": draw_type,
        "skip": 0,
    })

    import subprocess
    import os
    cmd = [
        "ffmpeg", "-y",
        "-hide_banner",
        "-f", "image2",
        "-framerate", "10", 
        "-i", "frame_%05d.png", 
        "-c:v", "libx264", 
        "-profile:v", "main", 
        "-pix_fmt", "yuv420p", 
        "-vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2",
        "-an", 
        "-movflags", "+faststart",
        os.path.join("animations", "animation_%02d%s.mp4" % (get_desc()[0], file_extra)),
    ]
    print("$ " + " ".join(cmd))
    subprocess.check_call(cmd)
Exemplo n.º 10
0
def other_draw(describe, values):
    if describe:
        return "Animate this"

    from dummylog import DummyLog
    targets = []
    rows = []
    for cur in values[:50]:
        rows.append(calc(DummyLog(), [cur], 2, target=[], pad=0))
    total = sum([int(x.strip()) for x in rows])
    pad = len(str(total))
    rows = []

    for cur in values[:50]:
        targets.append([])
        rows.append(calc(DummyLog(), [cur], 2, target=targets[-1], pad=pad))

    from grid import Grid
    disp = Grid(default=' ')

    while True:
        updates = 0
        y = 0
        for target in targets:
            while len(target) > 0:
                updates += 1
                cur = target.pop(0)
                if cur is None:
                    break
                disp[cur[0], y] = [cur[1], cur[2]]
            y += 1
        if updates == 0:
            break
        disp.draw_grid(show_lines=False,
                       default_color=(0, 0, 0),
                       font_size=13,
                       cell_size=(11, 19),
                       color_map={})

    while len(rows) >= 2:
        for x in range(pad):
            disp[x, 0][1] = (128, 128, 0)
            disp[x, 1][1] = (128, 128, 0)
        disp.draw_grid(show_lines=False,
                       default_color=(0, 0, 0),
                       font_size=13,
                       cell_size=(11, 19),
                       color_map={})
        for x in range(pad):
            disp[x, 0][1] = (0, 0, 0)
            disp[x, 1][1] = (0, 0, 0)
        for x in range(pad):
            for y in disp.y_range():
                disp[x, y] = [' ', (0, 0, 0)]
        temp = str(int(rows[0].strip()) + int(rows[1].strip()))
        temp = " " * pad + temp
        temp = temp[-pad:]
        rows = [temp] + rows[2:]
        for y in range(len(rows)):
            for x in range(len(rows[y])):
                disp[x, y] = [rows[y][x], (0, 0, 0)]
        disp.draw_grid(show_lines=False,
                       default_color=(0, 0, 0),
                       font_size=13,
                       cell_size=(11, 19),
                       color_map={})

    import subprocess
    import os
    cmd = [
        "ffmpeg",
        "-y",
        "-hide_banner",
        "-f",
        "image2",
        "-framerate",
        "10",
        "-i",
        "frame_%05d.png",
        "-c:v",
        "libx264",
        "-profile:v",
        "main",
        "-pix_fmt",
        "yuv420p",
        "-vf",
        "pad=ceil(iw/2)*2:ceil(ih/2)*2",
        "-an",
        "-movflags",
        "+faststart",
        os.path.join("animations", "animation_%02d.mp4" % (get_desc()[0], )),
    ]
    print("$ " + " ".join(cmd))
    subprocess.check_call(cmd)
Exemplo n.º 11
0
def other_draw(describe, values):
    if describe:
        return "Animate this"
    else:
        from dummylog import DummyLog
        calc(DummyLog(), values, 1, draw=True)
Exemplo n.º 12
0
def other_debug(describe, values):
    if describe:
        return "Debug mode on the second part"

    from dummylog import DummyLog
    calc(DummyLog(), values, True, debug=True)
Exemplo n.º 13
0
def other_log(describe, values):
    if describe:
        return "Log network traffic"
    from dummylog import DummyLog
    calc(DummyLog(), values, use_nat=True, log_traffic=True)
    print("Done")
Exemplo n.º 14
0
def main(lines):
    sys.path.insert(0, os.path.join('..', '..', 'Helpers'))

    from grid import Grid
    from dummylog import DummyLog
    from program import Program

    SIF = False

    Program.debug(lines)
    msg = datetime.utcnow()

    g = Grid(default=" ")
    p = Program([int(x) for x in lines.split(",")], DummyLog())
    width, height = None, None
    x, y = 0, 0
    while p.flag_running:
        p.tick()
        if width is None and SIF:
            if len(p.output) == 2:
                width, height = p.get_output(to_get=2)
                print(width, height)
        else:
            if len(p.output) == (1 if SIF else 3):
                if SIF:
                    i = p.get_output()
                else:
                    x, y, i = p.get_output(to_get=3)

                if datetime.utcnow() >= msg:
                    msg += timedelta(seconds=5)
                    print("x: %4d, y: %4d, %3d, '%s'" % (x, y, i, chr(i)))

                g.set(x, y, chr(i))

                if SIF:
                    x += 1
                    if x >= width:
                        y += 1
                        x = 0

    g.show_grid(DummyLog(), dump_all=True)
    g.draw_grid(color_map={
        " ": (0, 0, 0),
        "a": (0, 0, 170),
        "b": (0, 170, 0),
        "c": (0, 170, 170),
        "d": (170, 0, 0),
        "e": (170, 0, 170),
        "f": (170, 85, 0),
        "g": (170, 170, 170),
        "h": (85, 85, 85),
        "i": (85, 85, 255),
        "j": (85, 255, 85),
        "k": (85, 255, 255),
        "l": (255, 85, 85),
        "m": (255, 85, 255),
        "n": (255, 255, 85),
        "o": (255, 255, 255),
        "9": (0, 0, 0),
        "0": (0, 0, 170),
        "1": (0, 170, 0),
        "2": (0, 170, 170),
        "3": (170, 0, 0),
        "4": (170, 0, 170),
        "5": (170, 85, 0),
        "6": (170, 170, 170),
        "7": (85, 85, 85),
        "8": (85, 85, 255),
    },
                cell_size=(2 if SIF else 5),
                show_lines=(False if SIF else True))