Ruby, 105 characters
d=0
loop{s=(1..9).map{" "*79}
79.times{|i|s[(Math.sin((i+d)*Math::PI/16)*4+4.5)][i]=?x}
puts"^[[H",s
d+=1}
The ^[
is a single escape character. (You can enter it with Ctrl-V,Esc in the terminal and Vim or Ctrl-Q,Esc in MCEdit and Emacs.)
The animation is displayed from the 2nd line of top left corner of the terminal and scrolls from right to left at full speed (add sleep 0.1;
before the last }
to slow it down).
Sample run:
bash-4.4$ ruby -e 'd=0;loop{s=(1..9).map{" "*79};79.times{|i|s[(Math.sin((i+d)*Math::PI/16)*4+4.5)][i]=?x};puts"^[[H",s;d+=1}'
xxxxx xxxxx
xx xx xx xx
xx xx xx xx
x x x x
x x x x x
x x x x x
xx xx xx xx xx xx
xx xx xx xx xx xx
xxxxx xxxxx xxxxx
Ruby: 115 characters
d=0
while 1
s=(1..9).map{" "*79}
79.times{|i|s[(Math.sin((i+d)*Math::PI/16)*4+4.5)][i]=?x}
$><<"\e[H"+s*$/
d+=1
end
The animation is displayed in the top left corner of the terminal and scrolls from right to left at full speed (add sleep 0.1;
before the end
keyword to slow it down).
Sample run:
xxxxx xxxxx
xx xx xx xx
xx xx xx xx
x x x x
x x x x x
x x x x x
xx xx xx xx xx xx
xx xx xx xx xx xx
xxxxx xxxxx xxxxx
bash-4.1$ ruby -e 'd=0;while 1;s=(1..9).map{" "*79};79.times{|i|s[(Math.sin((i+d)*Math::PI/16)*4+4.5)][i]=?x};$><<"\e[H"+s*$/;d+=1;end'
(I know, can be shortened by replacing Math::PI/16
with its precalculated value of arbitrary precision. For example to 107 characters by using 0.2 multiplier. But the lower the precision, the uglier the output. May edit it in the future, I just keep it for now.)
2
Could you expand the specification? As it stands, I'm not sure what you're looking for. I'm also not sure what the scoring system is. See the description of on topic questions.
– Peter Taylor – 2013-06-24T17:52:23.690define "distinguishable". Does it suffice that a triangle wave would produce at least one pixel differently under any rounding mode? – John Dvorak – 2013-06-24T18:17:29.217
@FKunecke: If you're simply searching for a tool to plot functions: http://martin-thoma.com/html5/polynom-interpolation.htm
– Martin Thoma – 2013-07-02T19:57:03.923Does it have to actually be a sine wave, or does a curve that just looks like a sine wave count as good enough? – AJMansfield – 2013-07-12T13:45:39.607