| 3348 | // Based on: L. Spagnolini, 2007, http://dem.ocracy.org/libero/photobooth/ |
| 3349 | |
| 3350 | function polar(img, x0, y0, callback) { |
| 3351 | /* Returns a new Image based on a polar coordinates filter. |
| 3352 | * The given callback is a function(distance, angle) that returns new [distance, angle]. |
| 3353 | */ |
| 3354 | x0 = img.width / 2 + (x0 || 0); |
| 3355 | y0 = img.height / 2 + (y0 || 0); |
| 3356 | var p1 = new Pixels(img); |
| 3357 | var p2 = new Pixels(img); |
| 3358 | for (var y1=0; y1 < p1.height; y1++) { |
| 3359 | for (var x1=0; x1 < p1.width; x1++) { |
| 3360 | var x = x1 - x0; |
| 3361 | var y = y1 - y0; |
| 3362 | var d = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); |
| 3363 | var a = Math.atan2(y, x); |
| 3364 | var v = callback(d, a); d=v[0]; a=v[1]; |
| 3365 | p2.set(x1 + y1 * p1.width, p1.get( |
| 3366 | Math.round(x0 + Math.cos(a) * d) + |
| 3367 | Math.round(y0 + Math.sin(a) * d) * p1.width |
| 3368 | )); |
| 3369 | } |
| 3370 | } |
| 3371 | p2.update(); |
| 3372 | return p2.image(); |
| 3373 | } |
| 3374 | |
| 3375 | function bump(img, dx, dy, radius, zoom) { |
| 3376 | /* Returns the image with a dent distortion applied to it. |