什么是让使用算法GIF动画的最佳方式? [英] What's the best way to make an animated GIF using an algorithm?

查看:331
本文介绍了什么是让使用算法GIF动画的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个算法对不同大小的棋盘骑士之旅(大尺寸,如100×100),我想结果动画。每次骑士移动到一个新的正方形,则(正方形)画布中的对应像素会改变颜色,直到最终整个画布着色为,得到的电影将可观看关于算法的网页上。

I have an algorithm for knight's tours on chessboards of various sizes (large sizes, like 100x100) and I'd like to animate the result. Each time the knight moves to a new square, a corresponding pixel in the (square) canvas will change colours, until eventually the whole canvas is coloured in. The resulting movies will be available for viewing on a web page about the algorithm.

GIF动画似乎是最好的方法,如果我想广泛的浏览器支持(尽管其他建议,欢迎)。什么是最好的工具或图书馆使用做到这一点?我很高兴地使用任何免费提供的Linux或Mac电脑上。

Animated GIFs seem like the best method if I want broad browser support (though other suggestions are welcome). What is the best tool or library to do this with? I'm happy to use anything that's freely available on a Linux or Mac computer.

实际的算法太长做出了有益的例子在这里(见的如果你真的很好奇),但是本文这里的伪$ C $下一个(无聊)的国王的的游一个8x8板:

The actual algorithm is too long to make a useful example here (see this paper if you're really curious) but here's pseudocode for a (boring) king's tour on an 8x8 board:

movie = new Movie()
frame = new Frame()
frame.fillRectangle((1,1), 8, 8, BLUE)
for row in [1..8] {
    if (row.isOdd()) { colrange = [1..8] } else { colrange = [8..1] }
    for col in colrange {
        frame.colourPixel(row, col, RED)
        movie.addFrame(frame)
    }
}
movie.saveAsGIF("tour.gif")

超额信贷的问题:的我们可以采取的特殊功能,这部电影以减少文件大小的优势在哪里?该维基百科的文章表明,我们也许能够做这一点,如果我们仅仅改变一些像素的 - 事实上,我们只更改每帧

Extra-credit question: can we take advantage of the special features of this movie to reduce the file size? The Wikipedia article suggests that we might be able to do this, if we are only changing some of the pixels - in fact we are only changing one per frame!

推荐答案

您可以使用 giflib 以做到这一点。文件在下载。

You can use giflib to accomplish this. Documentation is in the download.

作为一个例子,此页面包含使用giflib和源$ C创建动画GIF $ c键用于生成动画节目。可能有助于了解如何使用giflib的动画。

As an example, this page contains animated gifs created using giflib and source code to the program used to generate the animations. Might be helpful to see how to use giflib for animations.

编辑:的另一种选择,如果你不介意的一些后期处理,是简单地输出使用一个简单的格式(的如PPM ),然后的>让gif动画。

Another alternative, if you don't mind some post-processing, is to simply output your frames using a simple format (such as PPM) and then make the animated gif using ImageMagick.

至于你加分的问题:ImageMagick的甚至可以做到框架比较的为您减少了输出的大小。

As for your extra credit question: ImageMagick can even do frame comparisons for you to reduce the size of the output.

这篇关于什么是让使用算法GIF动画的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆