MCPcopy Index your code
hub / github.com/clips/pattern / polar

Function polar

pattern/canvas.js:3350–3373  ·  view source on GitHub ↗
(img, x0, y0, callback)

Source from the content-addressed store, hash-verified

3348// Based on: L. Spagnolini, 2007, http://dem.ocracy.org/libero/photobooth/
3349
3350function 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
3375function bump(img, dx, dy, radius, zoom) {
3376 /* Returns the image with a dent distortion applied to it.

Callers 5

bumpFunction · 0.85
dentFunction · 0.85
pinchFunction · 0.85
splashFunction · 0.85
twirlFunction · 0.85

Calls 2

getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…