()
| 137 | |
| 138 | //Source: https://stackoverflow.com/questions/29586754/how-can-i-recreate-this-wavy-image-effect |
| 139 | function createAnimation() { |
| 140 | playAnimationToggle = true; |
| 141 | |
| 142 | var ctx = animation.getContext("2d"); |
| 143 | var w = scaledWidth; |
| 144 | var h = scaledHeight; |
| 145 | |
| 146 | //document.documentElement.style.width = scaledWidth; |
| 147 | |
| 148 | //ctx.drawImage(this, 0, 0); |
| 149 | //ctx.drawImage(originalImg, 0, 0); |
| 150 | |
| 151 | // source grid lines |
| 152 | x0 = 0, x1 = w * 0.25, x2 = w * 0.5, x3 = w * 0.75, x4 = w, |
| 153 | y0 = 0, y1 = h * 0.25, y2 = h * 0.5, y3 = h * 0.75, y4 = h; |
| 154 | |
| 155 | var maxXShift = scaledHeight*0.25; |
| 156 | var maxYShift = scaledWidth*0.25; |
| 157 | |
| 158 | // cache source widths/heights |
| 159 | sw0 = x1, sw1 = x2 - x1, sw2 = x3 - x2, sw3 = x4 - x3, |
| 160 | sh0 = y1, sh1 = y2 - y1, sh2 = y3 - y2, sh3 = y4 - y3, |
| 161 | |
| 162 | vcanvas = document.createElement("canvas"), // off-screen canvas for 2. pass |
| 163 | vctx = vcanvas.getContext("2d"); |
| 164 | |
| 165 | vcanvas.width = w; vcanvas.height = h; // set to same size as main canvas |
| 166 | |
| 167 | function loop() { |
| 168 | ctx.clearRect(0, 0, w, h); |
| 169 | |
| 170 | for (var y = 0; y < h; y++) { |
| 171 | |
| 172 | // segment positions for Y-waves |
| 173 | var lx1 = x1 + o1.current(y * 0.2) * maxYShift * yAmpInputValue/300, |
| 174 | lx2 = x2 + o2.current(y * 0.26) * maxYShift * yAmpInputValue/300, |
| 175 | lx3 = x3 + o3.current(y * 0.22) * maxYShift * yAmpInputValue/300, |
| 176 | |
| 177 | // segment widths |
| 178 | w0 = lx1, |
| 179 | w1 = lx2 - lx1, |
| 180 | w2 = lx3 - lx2, |
| 181 | w3 = x4 - lx3; |
| 182 | |
| 183 | // draw image lines |
| 184 | ctx.drawImage(originalImg, x0, y, sw0, 1, 0 , y, w0 , 1); |
| 185 | ctx.drawImage(originalImg, x1, y, sw1, 1, lx1 - 0.5, y, w1 + 0.5, 1); |
| 186 | ctx.drawImage(originalImg, x2, y, sw2, 1, lx2 - 0.5, y, w2 + 0.5, 1); |
| 187 | ctx.drawImage(originalImg, x3, y, sw3, 1, lx3 - 0.5, y, w3 + 0.5, 1); |
| 188 | |
| 189 | } |
| 190 | |
| 191 | // pass 1 done, copy to off-screen canvas: |
| 192 | vctx.clearRect(0, 0, w, h); // clear off-screen canvas (only if alpha) |
| 193 | vctx.drawImage(animation, 0, 0); |
| 194 | ctx.clearRect(0, 0, w, h); // clear main (onlyif alpha) |
| 195 | |
| 196 | for (var x = 0; x < w; x++) { |
no outgoing calls
no test coverage detected