# Print a sinusoidal wave (vertically)

Print a continuous sinusoidal wave scrolling vertically on a terminal. The program should not terminate and should continuously scroll down the wave (except until it is somehow interrupted). You may assume overflow is not a problem (i.e. you may use infinite loops with incrementing counters, or infinite recursion).

The wave should satisfy the following properties:

• Amplitude = 20 chars (peak amplitude)
• Period = 60 to 65 lines (inclusive)
• The output should only consist of spaces, newline and |
• After each line of output, pause for 50ms

Sample output:

                    |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|


The above output should go on forever unless otherwise interrupted, e.g. SIGINT or SIGKILL, or closing terminal window, or you power off your machine, or the Sun swallows the Earth, etc.

Shortest code wins.

Note. I am aware of a similar problem on Display Scrolling Waves but this isn't exactly the same. In my problem, the wave is not to be scrolled "in place" - just output it on a terminal. Also, this is an ascii-art problem, so don't use Mathematica to plot it.

• Peak amplitude, peak-to-peak amplitude, or root-square amplitude? – DavidC Jan 16 '14 at 20:31
• Peak amplitude. – user12205 Jan 16 '14 at 20:38
• Is it ok to draw a wave with just |s and no spaces? – Gelatin Jan 17 '14 at 1:23
• All answers yet are invalid. They also stop for SIGKILL not just for SIGINT. – bot47 Apr 4 '14 at 9:02
• @Max Ried fine, I will change it to "should go on forever unless otherwise interrupted". – user12205 Apr 4 '14 at 10:28

## TI-BASIC, 37

Executed from a TI-84 calculator

:While 1:DrawInv 2.9sin(X:ClrDraw:End

• Peak Amplitude = 20
• Period = 62
• Pause between lines 50-60 ms (very close as there is no built-in clock)
• OP: this is an ascii-art problem – MrZander Jan 17 '14 at 0:13
• almost all of the programming language answers use a predefined function for Sine, so I don't see how this would be against the rules. as this uses the predefined function for the language it is written in just the same as say Javascript – Malachi Jan 17 '14 at 0:44
• The problem @MrZander is trying to bring up here is that you're not doing this with ASCII characters, but by drawing a graph. That's against the rules. – joeytje50 Jan 17 '14 at 1:14
• No, DrawInv is a graphing feature of the TI-84, so this is just like using Mathematica to plot a sine wave. tibasicdev.wikidot.com/drawinv Also, all TI-84s have RTCs. – Kevin Chen Jan 17 '14 at 4:56
• I agree with @Kevin Chen that this is essentially just like using Mathematica to plot a sine wave. So, I still do not consider this to be a valid answer. Also, according to the picture in the link given by Kevin, I do not consider this to be ascii art. I think this is just some low resolution bitmap, so this answer does not qualify. – user12205 Jan 17 '14 at 16:42

## GTB, 14

Executed from a TI-84 calculator

[i;2.9sin(Xc;]


Amplitude = 20, Period = 62, Pause = ~50

• Since this is basically the same as your other answer, I consider this to be invalid as well. – user12205 Jun 14 '15 at 22:33

Groovy 87 Chars

Okay, now for a serious answer that actually follows the guidelines

def x=0;while(true){println ' '*(20*Math.sin(x)+20)+'|';x+=0.1;Thread.sleep(50)}

• Do you think a suitable decimal approximation for Math.PI/30 can save you a few chars? – user12205 Jan 17 '14 at 16:53

# CJam, 42 bytes

CJam is a bit younger than this challenge, but since this submission doesn't beat APL anyway, I don't see a problem with that.

es{es1$m50>{500d/ms21*K+S41*\i'|tN+oes}*}h  This won't work in the online interpreter, so you'll have to use the Java one. The basic idea is to keep a timestamp on the stack, and whenever 50 ms have passed since the last timestamp, a new line is printed (where the sine is computed from that last time), and a new timestamp left on the stack. # Pascal: 99 characters uses Crt;var i:Real;begin repeat Writeln('|':Round(Sin(i)*20+21));i:=i+0.1;Delay(500)until 0=1;end.  Another task where Pascal's output formatting comes handy and everything else is pain. # Julia, 60 chars Unlike CCP’s solution, mine uses a recursive function: a(n)=(print(" "^int(20sin(.1n)+20)*"|\n");sleep(.05);a(n+1))  Example: julia> a(1) | | | | | | | | | | | | | | | | | | | | | | | | | | |  # SmileBASIC, 44 bytes @L A=A+.1?" "*(COS(A)*20+20);"| WAIT 3GOTO@L  # PowerShell, 57 bytes for(;;sleep -m 50){' '*(20*[math]::Sin(($i+=.1))+20)+'|'}


Try it online!