Image distortion

Next we will add a more advanced effect. We will take the image and distort it with waves to make it look like a reflection in the water. We can do this using the Math.sin() method to offset the pixel positions from their original positions in a wavy pattern. So instead of changing color channels, this time we will be moving pixels around.

Get HTML5 Web Application Development By Example Beginner's guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.