Skip to content

Instantly share code, notes, and snippets.

@bildepunkt
Last active September 8, 2016 02:05
Show Gist options
  • Save bildepunkt/29bf0aa80ae828ec533ac78fd0bfead1 to your computer and use it in GitHub Desktop.
Save bildepunkt/29bf0aa80ae828ec533ac78fd0bfead1 to your computer and use it in GitHub Desktop.
draw an archimedian spiral approximation (w/ cubic bezier curves) in iDraw/Graphic
// spiral.idplugin
function drawSegment (doc, radius, iterations) {
var path = [doc addPath]
var spread = radius / 4
var c = 0.552284749
[path addMoveTo:CGPointMake(radius, 0)]
while (--iterations) {
var oldRadius
[path addCurveTo:CGPointMake(0, radius) controlPoint1:CGPointMake(radius, radius * c) controlPoint2:CGPointMake(radius * c, radius)]
oldRadius = radius
radius += spread
[path addCurveTo:CGPointMake(-radius, 0) controlPoint1:CGPointMake(-radius * c, oldRadius) controlPoint2:CGPointMake(-radius, oldRadius * c)]
oldRadius = radius
radius += spread
[path addCurveTo:CGPointMake(0, -radius) controlPoint1:CGPointMake(-oldRadius, -radius * c) controlPoint2:CGPointMake(-oldRadius * c, -radius)]
oldRadius = radius
radius += spread
[path addCurveTo:CGPointMake(radius, 0) controlPoint1:CGPointMake(radius * c, -oldRadius) controlPoint2:CGPointMake(radius, -oldRadius * c)]
}
return path;
}
function init() {
var doc = [app activeDocument]
var path = drawSegment(doc, 16, 12)
[[doc activeLayer] addPathShape:path]
}
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment