Example #1
0
def makeGifVideo(env,
                 actions,
                 initstate=None,
                 prefix='seq_',
                 duration=0.1,
                 outdir='../gifs/',
                 tmpdir='../temp/'):
    """ Generate an animated gif from a sequence of actions. """
    from external_libs.images2gif import writeGif
    import Image
    env.visualize = True
    env.reset()
    if initstate is not None:
        env.setState(initstate)
    env._counter = 1
    res_images = []
    astring = ''.join([str(a) for a in actions if a is not None])

    def cb(*_):
        fn = tmpdir + "tmp%05d.png" % env._counter
        pygame.image.save(env._game.screen, fn)
        res_images.append(Image.open(fn))
        env._counter += 1

    env.rollOut(actions, callback=cb)
    writeGif(outdir + prefix + '%s.gif' % astring,
             res_images,
             duration=duration,
             dither=0)
Example #2
0
def makeGifVideo(env, actions, initstate=None, prefix='seq_', duration=0.1,
                 outdir='../gifs/', tmpdir='../temp/'):
    """ Generate an animated gif from a sequence of actions. """
    from external_libs.images2gif import writeGif
    import Image
    env.visualize = True
    env.reset()
    if initstate is not None:
        env.setState(initstate)
    env._counter = 1
    res_images = []
    astring = ''.join([str(a) for a in actions if a is not None])
    
    def cb(*_):
        fn = tmpdir + "tmp%05d.png" % env._counter
        pygame.image.save(env._game.screen, fn)
        res_images.append(Image.open(fn))
        env._counter += 1
        
    env.rollOut(actions, callback=cb)
    writeGif(outdir + prefix + '%s.gif' % astring, res_images, duration=duration, dither=0)