保存框架以归档而无需渲染
在处理中,如何修改现有草图将每个帧保存到图像文件,以免将其渲染到屏幕上?
我在 https://forum.processing.org/one/topic/how-can-i-save-calculate-frame-frame-without-displaying-them-them-in-real-real time.html 可以使用pgraphics
将图形绘制到离线缓冲区中,这似乎是我追求的,但是我不确定如何轻松修改现有的草图以使用pgraphics < /代码>以这种方式进行类。
最重要的是,如果需要,我希望通过设置切换变量来呈现屏幕。
是否有一种简单的方法来“翻新”现有草图,以便它可以使用pgraphics
而不是默认渲染方法(例如,在setup
方法中),所以我我不喜欢t必须进入我的草图并更改每个绘制命令?
In Processing, how can I modify an existing sketch which saves each frame to an image file so that it does not render to the screen?
I saw in https://forum.processing.org/one/topic/how-can-i-save-calculate-frame-without-displaying-them-in-real-time.html that you can use PGraphics
to draw graphics into an offline buffer, which seems like it would be what I am after, but I am not sure how I can easily modify my existing sketch to use the PGraphics
class in that way.
On top of this, I would like the option to render to screen as well if needed by setting a toggle variable.
Is there an easy way of "retrofitting" an existing sketch so that it can use PGraphics
instead of the default rendering method (say, in the setup
method) so I don't have to go into my sketch and change every single draw command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
pgraphics
对象,并像使用画布一样借鉴它。这是一个示例草图,没有绘制循环,它输出图像文件:在我的草图文件夹中,它创建了此文件:
关于另一个问题:我认为您不能将书面的拉动循环改造成一个类似的输出而无需在草图的窗口中渲染它而不会大量修改代码,但是...如果您的目标是在绘制到草图窗口或文件之间的选择,则可以在每个帧中绘制Pgraphics并选择是否您想显示Pgraphics或不依赖您的业务规则。您仍然有很多重构要做,但这是不可避免的。
这是比以前相同的例子,但是实施了这个想法:
希望这会有所帮助。玩得开心!
You can use a
PGraphics
object and draw on it just like you would with a canvas. Here's an example sketch with no draw loop which outputs an image file:In my sketch's folder, it created this file:
About the other question: I don't think that you can retrofit a written draw loop into a similar output without rendering it in the sketch's window without heavily modifying the code, BUT... if your goal is yo be able to choose between drawing to the sketch window or to a file, you can draw in PGraphics every frame and choose whether if you want to show the PGraphics or not depending on your business rules. You'll still have a lot of refactoring to do, but it's unavoidable.
Here's the same example than before, but implementing this idea:
Hope this helps. Have fun!