Created
December 5, 2018 04:55
-
-
Save jusleg/f9b1668255cef724a930b326eb0559ec to your computer and use it in GitHub Desktop.
Draw cool loops in your terminal
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
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