O'Reilly logo

HTML5 Web Application Development By Example Beginner's guide by J.M. Gustafson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – making waves

Let's add the menu item for our wave effect. We give it a data-value custom attribute set to makeWaves:

<li data-value="makeWaves">Waves</li>

Now we will code the makeWaves() method. It will take four parameters; canvas, amplitude, frequency, and phase. amplitude determines how big the waves will be, frequency determines how many waves there are, and phase determines where the waves begin. Like the toSepia() method we will only pass in the canvas parameter, but you can try different parameters to see what effect they have:

function makeWaves(canvas, amplitude, frequency, phase) { amplitude = amplitude || 10; frequency = frequency || 4; phase = phase || 0; var data = getImageData(canvas).data; var newImageData = getImageData(canvas); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required