canvas 水波效果
看到某些工具上有水波效果,想能不能用canvas实现呢,于是就google了一下还真有在这里与大家分享吧! 这里有一篇教程,介绍实现原理的, 水波纹原理 下面是js实现的源代码 var ripple = (function(img_src, container){ var img = new Image, img_data, delay = 30, width, height, half_width, half_height, riprad = 5, oldind, newind, mapind, size, ripplemap = [], last_map = [], ripple, ripple_data, texture, texture_data, is_running = true, is_disturbed = false, timer_id, canvas = document.createElement('canvas'), /** @type {CanvasRenderingContext2D} */ ctx; function init(){ width = img.width; height = img.height; half_width = width >> 1; half_height = height >> 1; size = width *