Created
December 8, 2021 21:12
-
-
Save justvanrossum/d651fdc1b88cd33a51797403901a4802 to your computer and use it in GitHub Desktop.
[DrawBot] Given a circle radius and a pen thickness, create a spiral-ish path that fills a circle
This file contains 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
# https://twitter.com/rosettatype/status/1468660017993854980 | |
def plotter_circle_spiral(bez, center, radius, penWidth): | |
H = 0.5522847498 # Bezier circle magic constant | |
radius -= penWidth / 2 | |
numRevolutions = ceil(radius / penWidth + 1) | |
xRadius = yRadius = radius | |
radiusDelta = radius / (numRevolutions - 1) | |
cx, cy = center | |
bez.moveTo((cx + radius, cy)) | |
dx, dy = 1, 0 | |
for i in range(4 * numRevolutions): | |
h1x = xRadius * (dx - dy * H) | |
h1y = yRadius * (dy + dx * H) | |
h2x = xRadius * (-dy + dx * H) | |
h2y = yRadius * (dx + dy * H) | |
x = xRadius * -dy | |
y = yRadius * dx | |
bez.curveTo((cx + h1x, cy + h1y), (cx + h2x, cy + h2y), (cx + x, cy + y)) | |
dx, dy = -dy, dx | |
if not (i + 1) % 4: | |
yRadius -= radiusDelta | |
if i > 2 and not i % 4: | |
xRadius -= radiusDelta | |
radius = 320 | |
penWidth = 130 | |
bez = BezierPath() | |
plotter_circle_spiral(bez, (500, 500), radius, penWidth) | |
lineJoin("round") | |
lineCap("round") | |
fill(None) | |
stroke(0.8) | |
strokeWidth(penWidth) | |
drawPath(bez) | |
stroke(0) | |
strokeWidth(2) | |
drawPath(bez) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment