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.)