Pygame water ripple effect
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.
A good example, different from the Flash effect but that is still good is Water Simulation using Java applet.
(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’).
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).
Quoting the very developer behind Last Light Productions and the former Project Geometrian, Ian Mallet:
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.
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 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,
Can anyone provide a suitable implementation of this effect using OpenCV/OpenGL and Pygame?
Yes. Check Ogre3D’s water demo, provided with the SDK — and plug it into Python via Python-Ogre.
Источник
What Causes Ripples In Water?
Ripples in water are more formally known as capillary waves, and are caused by the subtle interaction of wind and water, or the physical interaction of the water with another object.
Have you ever stood at the edge of a lake on a hot summer day and stared out across the water? Even if there isn’t a whisper of wind against your face, you will likely still see faint lines and irregularities in the water. The light will reflect off movement at the surface, and small ripples will be seen in patches, sometimes appearing to move in different directions. Imagine picking up a stone and chucking it into the lake, where it lands with a satisfying splash, and an expanding ring of ripples will appear.
How are these created? (Photo Credit : YJ.K/Shutterstock)
These patterns and shapes that we see or create in water bodies are commonly referred to as ripples, but why do they form and what affects how long they last?
What is a Ripple?
Even on a day when you don’t feel any wind, there will always be some movement in the air, and at the surface of a water body, that movement causes small ripples to form. Wind energy is being transferred to the minuscule water molecules, which begin to move up and down, gently rising and falling, pulling along with the molecules beside them. However, the surface tension of water is quite strong, due to the polar nature of water molecules, and this tension will stop the ripples from perpetuating very far or for very long. The energy transferred into the water is quickly used up in moving those molecules up and down, so the ripples fade. This is what gives the ripples on a lake their transient, sparkling appearance, as they briefly rise and catch the light before settling back into stillness.
When you throw a rock into a body of water, the rock will push water out of its way as it enters, causing ripples to move away from its point of entry in a circle or ring shape. Water will then rush back in to fill the empty space, which can often cause a splash, resulting in more ripples forming. You can try this yourself by dropping a marble straight down into a bowl of water. Watch the resultant splash rise straight up and then fall back in, sending out a second ring of ripples. The larger the rock, the greater the effect and the stronger the ripple, meaning that it will last longer before disappearing. The reason that these ripples don’t behave like waves on a beach is because they aren’t strong enough; they lack the energy to persist in the face of water’s strong surface tension.
These types of ripples may also form when water is moving in a certain direction and encounters an obstacle, such as a fishing boat, a breakwall, or even your feet as they dangle off a dock! Water molecules will encounter an object and move upwards against it, before being pulled back down by the neighboring molecules. This interaction causes a ripple to form that moves in the opposite direction of the water’s initial motion.
Now, while a ripple is a type of wave motion—a capillary wave, to be precise—when we are talking about water bodies, there is a clear difference between a ripple and a wave.
Ripples vs Waves vs Swells
As mentioned above, a ripple is a transient, short-lived phenomena that quickly disappears once its input energy is used up. However, if wind continually moves over a body of water, creating a steady stream of ripples, they can begin to accrue more energy, and will turn into waves, like those you might see crashing on a beach. While ripples are unable to overcome the force of surface tension, waves can build up enough energy to do so if the wind blows steadily over a large enough patch of water. Such waves will always flow in the same direction as the wind, and will shift direction if the wind changes.
When waves move into shallower water, the bottom part of the wave will decrease in speed, and the top part of the wave will overtake it, causing the wave to break. This can also be seen in the ocean open, particularly during a storm or when the seas are choppy, i.e., when different weather systems are interacting, or when the wind is rapidly changing direction.
If the wind is persistent and strong, it can begin to generate the most persistent type of movement—a swell. While waves always move in the same direction as the wind, a swell forms when those waves move out of the area they were initially made. The water of a swell has gathered enough energy and momentum that it can actually move against the wind, sometimes traveling vast distances, across entire oceans, without losing its energy. A swell is typically difficult to see against the horizon, as it is often longer, more even and slower-moving than normal waves. Also, the distance between the troughs and peaks of a swell is usually much greater than that distance in waves formed by the wind.
A Final Word
Clearly, water is able to store and harness a lot of wind energy under the right conditions, but ripples are simply too transient, too small and have too little energy to persist and travel for long distances. However, if you get a large enough rock and drop it from a high enough height, you may be able to create a ripple that travels out from the middle of the lake to the shoreline!
Источник
What is ripple effect in water
This library was created by Lars Birkemose on 02/12/11 and edited by guanghui on 7/30/13. Now I have custom it for compatible for both cocos2dx version 2x and version 3x. It work well for iOS 8+ and Android 19+
What is a Ripple effect ?
Ripple effect is a situation in which, like ripples expand across the water when an object is dropped into it, an effect from an initial state can be followed outwards incrementally.
There is really nothing special to the ripple effect, in essence it is just an evaluation of the sombrero function
A sombrero function (sometimes called besinc function or jinc function) is the 2-dimensional polar coordinate analog of the sinc function, and is so-called because it is shaped like a sombrero hat. This function is frequently used in image processing. It can be defined through the Bessel function of the first kind where :
With Riple Effect just use 2D version of sombrero function and with
The WebGL version of Ripple effect can see here
Источник
Ripple Effect
Ripple Effect is a nonprofit environmental education organization that fosters water literacy through professional training and standards-aligned curricula, so teachers can incorporate real-world, climate-related water issues into everyday science instruction.
We develop standards-aligned science curricula about real communities impacted by climate-related water challenges, then provide in-depth teacher training programs that prepare teachers to teach this curriculum with fidelity.
Read our Strategic Plan.
What is water literacy?
Water literacy is the systematic collection and sharing of knowledge, skills, and ethical grounding that all individuals and communities need to successfully adapt to changing hydrologic conditions. It encompasses the environmental, economic, and social dimensions of human connections to water, water infrastructure, and aquatic ecosystems.
Water Literacy…
- consists of the knowledge, skills, and ethical grounding necessary to successfully adapt to changing hydrologic conditions.
- encompasses the environmental, economic, and social dimensions of human connections to water.
draws from science, the humanities, social science, and community expertise to define and address water issues. - occurs in formal and informal contexts across the human developmental lifespan.
- values both traditional ecological knowledge and Western modern science.
- is rooted in a socioecological context in which human beings and nature are inextricably intertwined.
- is inherently local, reflecting the ecologies, social histories, and economies of specific geographic regions.
Impacts
Students living in our most climate-vulnerable coastal regions will receive regular, high-quality science instruction about water issues from prepared, passionate, and knowledgeable teachers in every grade, K-12.
This will result in a critical mass of students who are water literate by the time they graduate, widening the pipeline of minority and low-income students into fields such as science, policy, and engineering, where they can champion innovative and equitable climate change solutions. This will enhance community engagement with and support for these solutions, leading to improved health and sustainability outcomes for coastal communities.
Outcomes
We aim to dramatically impact water literacy outcomes for a critical mass of teachers and students in coastal communities:
- Increased investment in water literacy; improved connection between scientific research and K-12; greater demand for in-school water literacy education as part of everyday science instruction.
- Increased teacher content knowledge; improved instruction on real-world water and climate issues.
- Increased student knowledge of social and scientific dimensions of complex, ethically tricky climate-related water challenges; greater awareness of real-world practices needed to tackle these challenges.
Источник