Created
November 2, 2016 03:18
-
-
Save drhuffman12/a15501a63ce4305bb6194db2a61f39f0 to your computer and use it in GitHub Desktop.
simple txt grapher
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
def stars(y,scale,char);y>0 ? char * ((y*scale).round) : '';end | |
def curve(n);(0..n+1).each.collect{|x| y=Math.sin(Math::PI*2*x/n); [x, y]};end | |
def star_set(y,scale,char_neg,char_zero,char_pos); yn = y < 0 ? stars(-y,scale,char_neg) : ''; yp = y > 0 ? stars(y,scale,char_pos) : ''; ("%#{scale.round.to_i}s" % yn) + char_zero + ("%-#{scale.round.to_i}s" % yp); end | |
def star_set_def(y);star_set(y,10,'-','.','+');end | |
puts curve(16).collect{|n| star_set_def(n[1])+" #{n[0]}, #{n[1]}\n"}.join('') | |
=begin | |
. 0, 0.0 | |
.++++ 1, 0.3826834323650898 | |
.+++++++ 2, 0.7071067811865475 | |
.+++++++++ 3, 0.9238795325112867 | |
.++++++++++ 4, 1.0 | |
.+++++++++ 5, 0.9238795325112867 | |
.+++++++ 6, 0.7071067811865476 | |
.++++ 7, 0.3826834323650899 | |
. 8, 1.2246467991473532e-16 | |
----. 9, -0.38268343236508967 | |
-------. 10, -0.7071067811865475 | |
---------. 11, -0.9238795325112865 | |
----------. 12, -1.0 | |
---------. 13, -0.9238795325112866 | |
-------. 14, -0.7071067811865477 | |
----. 15, -0.3826834323650904 | |
. 16, -2.4492935982947064e-16 | |
.++++ 17, 0.38268343236508995 | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment