コード例 #1
0
def run(clock=None,
        framerate=None,
        interactive=None,
        duration=sys.maxsize,
        framecount=sys.maxsize):
    """ Run the main loop

    Parameters
    ----------
    clock : Clock
        clock to use to run the app (gives the elementary tick)

    framerate : int
        frames per second

    duration : float
        Duration after which the app will be stopped

    framecount : int
        Number of frame to display before stopping.
    """
    global __running__

    clock = __init__(clock=clock, framerate=framerate, backend=__backend__)
    options = parser.get_options()

    if interactive is None:
        interactive = options.interactive

    if interactive:
        # Set interactive python session
        os.environ['PYTHONINSPECT'] = '1'
        import readline
        readline.parse_and_bind("tab: complete")

        def run():
            while not stdin_ready():
                __backend__.process(clock.tick())
            return 0

        inputhook_manager.set_inputhook(run)

    else:
        __running__ = True

        def run(duration, framecount):
            count = len(__backend__.windows())
            while count and duration > 0 and framecount > 0 and __running__:
                dt = clock.tick()
                duration -= dt
                framecount -= 1
                count = __backend__.process(dt)

        if options.record:
            from .movie import record
            # Obtain the name of the script that is being run
            name = os.path.basename(sys.argv[0])
            # Replace .py extension with .mp4
            filename = re.sub('.py$', '.mp4', name)
            log.info("Recording movie in '%s'" % filename)
            with record(window=__backend__.windows()[0],
                        filename=filename,
                        fps=60):
                run(duration, framecount)
        else:
            run(duration, framecount)
コード例 #2
0
def run(clock=None,
        framerate=None,
        interactive=None,
        duration=sys.maxint,
        framecount=sys.maxint):
    """ Run the main loop

    Parameters
    ----------
    clock : Clock
        clock to use to run the app (gives the elementary tick)

    framerate : int
        frames per second

    duration : float
        Duration after which the app will be stopped

    framecount : int
        Number of frame to display before stopping.
    """
    global __running__

    clock = __init__(clock=clock, framerate=framerate, backend=__backend__)
    options = parser.get_options()

    if interactive is None:
        interactive = options.interactive

    writer = None
    if options.record:
        from glumpy.ext.ffmpeg_writer import FFMPEG_VideoWriter
        framerate = 60
        window = __backend__.windows()[0]
        width, height = window.width, window.height
        filename = "movie.mp4"
        writer = FFMPEG_VideoWriter(filename, (width, height), fps=framerate)
        fbuffer = np.zeros((height, width, 3), dtype=np.uint8)
        data = fbuffer.copy()
        log.info("Recording movie in '%s'" % filename)

    if interactive:
        # Set interactive python session
        os.environ['PYTHONINSPECT'] = '1'
        import readline
        readline.parse_and_bind("tab: complete")

        def run():
            while not stdin_ready():
                __backend__.process(clock.tick())
            return 0

        inputhook_manager.set_inputhook(run)

    else:
        __running__ = True
        count = len(__backend__.windows())
        while count and duration > 0 and framecount > 0 and __running__:
            dt = clock.tick()
            duration -= dt
            framecount -= 1
            count = __backend__.process(dt)

            # Record one frame (if there is writer available)
            if writer is not None:
                gl.glReadPixels(0, 0, window.width, window.height, gl.GL_RGB,
                                gl.GL_UNSIGNED_BYTE, fbuffer)
                data[...] = fbuffer[::-1, :, :]
                writer.write_frame(data)

        if writer is not None:
            writer.close()
コード例 #3
0
ファイル: __init__.py プロジェクト: drufat/glumpy
def run(clock=None, framerate=None, interactive=None,
        duration = sys.maxsize, framecount = sys.maxsize):
    """ Run the main loop

    Parameters
    ----------
    clock : Clock
        clock to use to run the app (gives the elementary tick)

    framerate : int
        frames per second

    duration : float
        Duration after which the app will be stopped

    framecount : int
        Number of frame to display before stopping.
    """
    global __running__

    clock = __init__(clock=clock, framerate=framerate, backend=__backend__)
    options = parser.get_options()

    if interactive is None:
        interactive = options.interactive

    if interactive:
        # Set interactive python session
        os.environ['PYTHONINSPECT'] = '1'
        import readline
        readline.parse_and_bind("tab: complete")

        def run():
            while not stdin_ready():
                __backend__.process(clock.tick())
            return 0
        inputhook_manager.set_inputhook(run)

    else:
        __running__ = True

        def run(duration, framecount):
            count = len(__backend__.windows())
            while count and duration > 0 and framecount > 0 and __running__:
                dt = clock.tick()
                duration -= dt
                framecount -= 1
                count = __backend__.process(dt)

        if options.record:
            from .movie import record
            # Obtain the name of the script that is being run
            name = os.path.basename(sys.argv[0])
            # Replace .py extension with .mp4
            filename=re.sub('.py$', '.mp4', name)
            log.info("Recording movie in '%s'" % filename)
            with record(window=__backend__.windows()[0],
                        filename=filename,
                        fps=60):
                run(duration, framecount)
        else:
            run(duration, framecount)
コード例 #4
0
ファイル: __init__.py プロジェクト: aimoaimo/glumpy
def run(clock=None, framerate=None, interactive=None,
        duration = sys.maxint, framecount = sys.maxint):
    """ Run the main loop

    Parameters
    ----------
    clock : Clock
        clock to use to run the app (gives the elementary tick)

    framerate : int
        frames per second

    duration : float
        Duration after which the app will be stopped

    framecount : int
        Number of frame to display before stopping.
    """
    global __running__

    clock = __init__(clock=clock, framerate=framerate, backend=__backend__)
    options = parser.get_options()

    if interactive is None:
        interactive = options.interactive

    writer = None
    if options.record:
        from glumpy.ext.ffmpeg_writer import FFMPEG_VideoWriter
        framerate = 60
        window = __backend__.windows()[0]
        width, height = window.width, window.height
        filename = "movie.mp4"
        writer = FFMPEG_VideoWriter(filename, (width, height), fps=framerate)
        fbuffer = np.zeros((height, width, 3), dtype=np.uint8)
        data = fbuffer.copy()
        log.info("Recording movie in '%s'" % filename)

    if interactive:
        # Set interactive python session
        os.environ['PYTHONINSPECT'] = '1'
        import readline
        readline.parse_and_bind("tab: complete")

        def run():
            while not stdin_ready():
                __backend__.process(clock.tick())
            return 0
        inputhook_manager.set_inputhook(run)

    else:
        __running__ = True
        count = len(__backend__.windows())
        while count and duration > 0 and framecount > 0 and __running__:
            dt = clock.tick()
            duration -= dt
            framecount -= 1
            count = __backend__.process(dt)

            # Record one frame (if there is writer available)
            if writer is not None:
                gl.glReadPixels(0, 0, window.width, window.height,
                                gl.GL_RGB, gl.GL_UNSIGNED_BYTE, fbuffer)
                data[...] = fbuffer[::-1,:,:]
                writer.write_frame(data)

        if writer is not None:
            writer.close()