![[screenshot]](https://habrastorage.org/storage2/590/c1e/8e5/590c1e8e5e666d22bce032b39c5da5f9.jpg)
The
lake.js script has
become known - a jQuery plugin that takes an illustration
(the <img> element) and places it on the canvas (inserts a
<canvas> element), having a mirror image immediately below it that goes like waves in a lake.
We are not talking about frozen waves, but about waves going through the water - their phase is dynamically changed by javascript. (It is clear that this effect is not reproducible on Habrahabr, so I insert a static screenshot.)
The canvas has the same width as the processed illustration, and twice the height.
')
Calling a plugin looks relatively simple and self-evident:
<script src="jquery.js"></script> <script src="lake.js"></script> <script> $(function() { $('#lake-img').lake({ 'speed': 1, 'scale': 0.5, 'waves': 10 }); }); </script> ... <img id="lake-img" src="lake.png" style="display: none;"/>
Parameters have the following meaning:
- speed - the speed of the waves;
- scale - height of the hump (amplitude) of the waves;
- waves - the number of waves.
Animation frames are compiled at the beginning of the script, so that after the initial page load (when
$ ( ... ) works), there may be a slowdown. The author of lake.js claims that the script works tolerably on most devices.