Skip to content

Instantly share code, notes, and snippets.

@jusleg
Created December 5, 2018 04:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jusleg/f9b1668255cef724a930b326eb0559ec to your computer and use it in GitHub Desktop.
Save jusleg/f9b1668255cef724a930b326eb0559ec to your computer and use it in GitHub Desktop.
Draw cool loops in your terminal
POINTS = 10000
PRE_ROTATION = Math::PI * 1
LOOPS = 5
DIMENSION = 101
values = Array.new(DIMENSION){Array.new(DIMENSION)}
middle = DIMENSION/2+1
POINTS.times do |i|
radius = DIMENSION / 2 * i / POINTS
angle = PRE_ROTATION + LOOPS * Math::PI * 2 * i / POINTS
x = middle + radius * Math.cos(angle)
y = middle + radius * Math.sin(angle)
values[y.round][x.round] = "\e[#{31 + (5 * i / POINTS).round}m* \e[0m"
end
counter = 0
values.each do |array_val|
array_val.each do |elem|
symbol = elem.nil? ? ' ' : elem
print symbol
counter += 1
end
print "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment