Skip to content

Instantly share code, notes, and snippets.

@blinry
Created October 23, 2017 22:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blinry/7cdc049293a75fc5ce7db0337856092b to your computer and use it in GitHub Desktop.
Save blinry/7cdc049293a75fc5ce7db0337856092b to your computer and use it in GitHub Desktop.
require 'victor'
scale = 1000 # scale up the result by this factor
first_n = 1 # index of first logo
last_n = 10000 # index of last logo
SCALE = 0.18 # scale up the individual logos by this factor
ALPHA = -15 # for smaller values, logos will shrink faster going out. for positive values, logos will shrink going in.
def get_r i
i**(1/(2.0-ALPHA))
end
def get_t i
i*137.507764/180*Math::PI # golden angle: 137.507764 degrees
end
def get_scl i
SCALE*Math.sqrt(get_r(i)**ALPHA)
end
def get_pos i
[get_r(i)*Math.sin(get_t(i)),
get_r(i)*Math.cos(get_t(i))]
end
w = 2*get_r(last_n)*scale # width of the final image
svg = Victor::SVG.new width: w, height: w
first_n.upto(last_n) do |n|
pos = get_pos(n)
scl = get_scl(n)
# circle
#svg.circle cx: 0, cy: 0, r: scl*scale, fill: "black", transform: "translate(#{pos[0]*scale+w/2.0}, #{pos[1]*scale+w/2.0})"
# arrow
#svg.path d: "M0 -0.5 L0.5 0 L0.2 0 L0.2 0.5 L-0.2 0.5 L-0.2 0 L-0.5 0 Z", fill: "black", transform: "translate(#{pos[0]*scale+w/2.0}, #{pos[1]*scale+w/2.0}) scale(#{scl*scale}) rotate(#{180-get_t(n)*180/Math::PI})"
# triangle
#svg.path d: "M0 -0.8 L0.5 0 L-0.5 0 Z", fill: "black", transform: "translate(#{pos[0]*scale+w/2.0}, #{pos[1]*scale+w/2.0}) scale(#{scl*scale}) rotate(#{180-get_t(n)*180/Math::PI})"
# heart
svg.path d: "M0 -1 L1 0 L 0 1 A0.7071 0.7071 0 0 1 -1 0 A0.7071 0.7071 0 0 1 0 -1 Z", fill: "black", transform: "translate(#{pos[0]*scale+w/2.0}, #{pos[1]*scale+w/2.0}) scale(#{scl*scale}) rotate(#{270-get_t(n)*180/Math::PI})"
end
svg.save "fibonacci-spiral.svg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment