Created
May 15, 2014 05:04
-
-
Save NathanFlurry/1cdfd6f83d48d5a26c2c to your computer and use it in GitHub Desktop.
Sketch 3D Extrusion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Math.lerp = function(a,b,f) { | |
return Number(a) + f * (Number(b) - Number(a)); | |
} | |
Math.radians = function(degrees) { | |
return degrees * Math.PI / 180; | |
}; | |
Math.degrees = function(radians) { | |
return radians * 180 / Math.PI; | |
}; | |
var app = [NSApplication sharedApplication]; | |
var amnt = [doc askForUserInput:"How far should the shadow be?" initialValue:"5"]; | |
var angle = [doc askForUserInput:"What is the angle (in degrees)?" initialValue:"-90"]; | |
var col1Str = [doc askForUserInput:"What is color 1?" initialValue:"0,0,0"]; | |
var col2Str = [doc askForUserInput:"What is color 1?" initialValue:"1,1,1"]; | |
var color1 = col1Str.split(","); | |
var color2 = col2Str.split(","); | |
var loop = [selection objectEnumerator]; | |
while (item = [loop nextObject]) { | |
// Clears current shadows | |
while (item.style().shadows().array().length() > 0) { | |
item.style().shadows().removeStylePartAtIndex(0); | |
} | |
// Adds shadows | |
for (var i = 0; i < amnt; i++) { | |
item.style().shadows().addNewStylePart(); | |
var shadow = item.style().shadows().array()[i] | |
var radAngle = Math.radians(angle) | |
shadow.offsetX = Math.cos(radAngle)*(i+1); | |
shadow.offsetY = Math.sin(radAngle)*(i+1); | |
shadow.blurRadius = 0; | |
var color = [[MSColor alloc] init]; | |
[color setRed:Math.lerp(color1[0],color2[0],i/amnt)]; | |
[color setGreen:Math.lerp(color1[1],color2[1],i/amnt)]; | |
[color setBlue:Math.lerp(color1[2],color2[2],i/amnt)]; | |
[color setAlpha:1]; | |
shadow.color = color; | |
[[[item style] shadows] moveStylePartFromIndex:i toIndex:0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment