Skip to content

Instantly share code, notes, and snippets.

@the-real-tokai
Created May 31, 2020 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-real-tokai/e3418ab5e573ff93b58cd9801d814dee to your computer and use it in GitHub Desktop.
Save the-real-tokai/e3418ab5e573ff93b58cd9801d814dee to your computer and use it in GitHub Desktop.
Draw a Series of Straight Upward Lines on a Circle that Is Shifted Horizontally in the Middle
#!/usr/bin/env python3
from math import pi, sin, cos, radians;
# Method: Draw a circle of points, shift all points to the left when drawing the upper half, shift all points to the right
# when drawing the lower half. At the end draw a straigh line going upwards on each point (or downwards… not sure
# which direction SVG is doing stuff. ;) )
#
# Note: Bunch of double calculations there, so this is not very optimized… :D
width = 1024
height = width
spacing = 264
radius = 200
print('<svg width="100%" height="100%" viewBox="0 0 {} {}" xmlns="http://www.w3.org/2000/svg">'.format(width, height),
'<g fill="black">',
''.join('<line x1="{x1}" y1="{y1}" x2="{x1}" y2="{y2}" stroke="rgba(240, 176, 0, 0.4)" stroke-linecap="round" stroke-width="5" />'.format(
x1=(sin(radians(a))*radius+(width/2))+(radius if (radians(a) < (pi/2)) else -radius),
y1=(cos(radians(a))*radius+spacing),
y2=(cos(radians(a))*radius+spacing)+(height-(2*spacing))
) for a in range(-90, 360-90, 2)),
'</g></svg>', sep='', end='')
# Ideas/ References:
# https://www.instagram.com/p/B6GcVQKoZ1u/
# https://old.reddit.com/r/generative/comments/gu540c/recreation_of_an_axidraw_sketch_i_found/
#
# Result:
# https://external.binaryriot.org/site-reddit-com/2020.05/31_axidraw_recreation.svg
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment