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); var newData = newImageData.data; var width = newImageData.width; var height = newImageData.height; // Adjust frequency to height of image frequency = frequency * 2 * Math.PI...