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.

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

EDIT:Can anyone provide a suitable implementation of this effect using OpenCV/OpenGL and Pygame?

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.

(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').

I got bored and implemented the algorithm from your first link using C++ and OpenCV (I haven't tried pygame yet). github.com/mpenkov/sandpit/tree/master/stackoverflow. It's not hard to implement, but it doesn't look as good as the Flash version in my link above. I still don't know why.
–
mishaOct 4 '11 at 18:31

1

@misha, I managed to run the code you put together on my Ubuntu VM. Awesome.
–
leonOct 4 '11 at 22:01

1

@misha, I would presume Pygame to be slower than sheer C++ code. I will later on try to port your implementation into pure Pygame and then Pygame + OpenGL and post results and/or source here. Should take me from one to three days.
–
leonOct 5 '11 at 6:06

2 Answers
2

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).

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

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.

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.

The following using numpy might get you started. It should be fast enough as it is though you could get much faster even in python (have a look here to see how http://www.scipy.org/PerformancePython).

By the way there are several drawbacks in the method described :

you cannot control the speed of the ripples - to do that you would have to modify the equations used in the ripple function (if you figure out how it relates to the wave equation http://en.wikipedia.org/wiki/Wave_equation then you are done)

the "depth" of the "pool" is fixed (and probably too shallow). I added a depth parameter to magnify the effect

the article reads integer pixel offsets - you would get a much nicer result with interpolated values (i guess you can do that with opengl, but my knowledge in that area is nil)