Skip to content

Instantly share code, notes, and snippets.

@kimballfrank
Created May 11, 2017 16:24
Show Gist options
  • Save kimballfrank/7d7abc977e6287604e9eadf2888bede5 to your computer and use it in GitHub Desktop.
Save kimballfrank/7d7abc977e6287604e9eadf2888bede5 to your computer and use it in GitHub Desktop.
function distortLayer(layer, shearHorizontallyBy, shearVerticallyBy) {
var shearVerticallyBy = shearVerticallyBy || 0;
if(!layer.isKindOfClass(MSShapeGroup)) return;
var path=layer.bezierPathWithTransforms();
var transform=DKDistortionTransform.transformWithInitialRect(layer.frame().rect());
transform.shearHorizontallyBy(shearHorizontallyBy);
transform.shearVerticallyBy(shearVerticallyBy);
var nextPath = transform.transformBezierPath(path);
layer.setBezierPath(nextPath);
doc.reloadInspector();
}
function shearByDegree(layer, angle) {
var offset=(Math.sqrt(Math.pow(layer.frame().height()/Math.cos(angle * (Math.PI/180)),2)-Math.pow(layer.frame().height(),2)))/2;
return (angle<0) ? -offset : offset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment