Pygame水波纹效果 [英] Pygame water ripple effect

查看:302
本文介绍了Pygame水波纹效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经谷歌搜索但没有现成的脚本 - 而不是对Flash的相同效果。我在水效应解释并测试了 Perlin Noise的实施,可以很好地模拟平面上的波浪末端。我正在寻找基于鼠标悬停/悬停操作在几个Flash Effects上找到的相同实现。这是针对一个交互式楼层库,我很乐意从这个问题转移到Flash,特别是为了避免代码的这种简单的逆向工程 - 是的,我知道它可以只使用一些现成的闪存代码,但我只会将其用作最后的手段。

I have Googled for it but there are no ready scripts - as opposed to the same effect on Flash. I have checked the algorithm on The Water Effect Explained and also tested an implementation of the Perlin Noise, which provides a good simulation of the end of waves on a flat surface. I am looking for the same implementation found on several Flash Effects, based on mouseover/hover actions. This is targetting an interactive floor library, and I would enjoy moving away from Flash for this matter, particularly to avoid such easy reverse-engineering of the code - and yes, I know it could just use some ready-made flash code, but I would only use that as a last resort.

有没有人为Pygame看过这种效果的合适实现(使用OpenGL与否)?

Has anyone seen a suitable implementation of this effect for Pygame (using OpenGL or not)?

编辑: 任何人都可以使用OpenCV / OpenGL和Pygame提供此效果的合适实现吗?

这里的罪魁祸首是(代码)接口传递一个值列表,这些值将通过Python从外部解释器(跟踪器 - 而不是TUIO)发送。我已经尝试了几天,但是Pygame无法像C / C ++代码那样快速生成任何东西(用于OpenGL中的着色器),而且我对C / C ++的了解也是空的。所以目标至少要来自Python代码。

The culprit here is the (code) interface to pass a list of values that will be sent from an external interpreter (tracker - not TUIO though) via Python. I have tried for some straight days but Pygame is not able to generate anything as fast as sheer C/C++ code (as used for the shaders in OpenGL), and my knowledge of C/C++ is null. So the target is to at least have that coming from Python code.

一个很好的例子,与Flash效果不同但是仍然很好是使用Java小程序进行水模拟

A good example, different from the Flash effect but that is still good is Water Simulation using Java applet.

(赏金)显示答案没有足够的细节,因为这是最接近'OP无法创建他想要的代码,因为他缺乏基本技能,这个答案可能对几个人有用')。

(bounty is showing answers do not have enough detail since this was the closest to 'the OP is incapable of creating the code he wants to as he lacks fundamental skills and this answer will probably be of use to several people').

推荐答案

做完作业(又名研究)并尝试将问题上发布的Java代码参考直接转换成Python,并且非常非常伤心尝试让Python / Numpy根据涟漪效果的波纹位置更新大量的像素颜色(抱歉,我的第一语言不是英语),从而解析每个传递的几个(x,y)位置效果计算在屏幕上显示的表面(随后是冲浪)上,我得出结论 - 这是由其他评论者支持的 - Pygame只是不会足够强大到实际上遍历整个像素阵列,并将计算结果应用到屏幕上的每个像素上,最低速率为24 fps(对于低于平均值的体验)。

After doing homework (a.k.a. research) and trying to directly convert the Java code reference posted on the question into Python, and having a very, very sad experience while trying to have Python/Numpy update a humongous array of pixel colors based on their positions for the rippling of the ripple effect (sorry, my first language isn't English), thus parsing several (x,y) positions for each pass of the effect calculations and blitting that onto the displayed surface on the screen (surfarray ensues), I've come to the conclusion - that is backed up by other commenters - that Pygame simply won't be powerful enough to actually traverse that entire array of pixels and apply results of calculations onto every pixel on the screen at a minimum rate of 24 fps (for a less-than-average experience).

引用 Last Light Productions 和前 Project Geometrian ,Ian Mallet:

Quoting the very developer behind Last Light Productions and the former Project Geometrian, Ian Mallet:


PyGame对像素推送不太好。除了GPU之外,什么都没有。

PyGame is not so good for pixel pushing. Nothing is, other than the GPU.

然后搜索结果是搜索 Alkahest - 结果永远不会真正找到 - 并且基于相同的波纹图像的想法,但这次通过使用透明度看穿几层Pygame表面,我发布了 Pygame圆形裁剪/面具的问题Gamedev。 选择的答案实际上证实了我已经担心Pygame永远不会这样的事实男子气概足以胜任这份工作。

The search then turned out to be a search for Alkahest - something that would turn out never to be truly found - and based on the same idea of rippling images, but this time by using transparency to see through several layers of Pygame surfaces, I posted the question Pygame circular cropping/masks on Gamedev. The chosen answer actually corroborates the fact I already feared that Pygame would never be macho enough for the job.

一天后,我又回到了我之前关于开发的想法并遇到了 Ogre3D 。事实证明(1)Ogre3D和样本是开源的(2)其中一个例子是与移动物体相互作用的三维水模型,与我试图在二维中实现的完全相同,但是以更专业的方式。

One day later I went back to my previous ideas on development and came across Ogre3D. It turns out that (1) Ogre3D and samples are open-source and (2) one of the examples is a 3-D water model that interacts with a moving object, exactly the same thing I tried to achieve in 2-D, but in a much more professional manner.

由于我对C / C ++的了解是零,我决定询问如何自定义Ogre3D水演示,一瞥从何处开始寻找,其中一个答案指向了Touchscape的软件,其中SDK是已提供(请参阅此答案)。

Since my knowledge in C/C++ is nil, I decided to ask about how to customize the Ogre3D water demo for a glimpse of where to start looking, and one of the answers pointed me to software from Touchscape where an SDK is provided (see this answer).

Ogre3D几乎把它包裹起来。水波纹效应,OpenGL(它可以可选使用基于硬件),游戏引擎和Python通过 Python-Ogre 包装 - 所以我回答了我自己的问题,

Ogre3D pretty much wrapped it up. Water ripple effect, OpenGL (which it may optionally use based on hardware), Game Engine and Python wrappers via Python-Ogre - so my answer to my own question,


任何人都可以使用OpenCV / OpenGL和Pygame提供这种效果的合适实现吗?

基本上是


是的。查看随SDK提供的Ogre3D的水演示 - 并通过 Python-Ogre 将其插入Python。

Yes. Check Ogre3D's water demo, provided with the SDK - and plug it into Python via Python-Ogre.

这篇关于Pygame水波纹效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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