Launch rocket with countdown and acceleration in stdout: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎{{header|REXX}}: added the REXX computer programming language for this task.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(29 intermediate revisions by 13 users not shown)
Line 1:
{{draft task}}
{{draft task|Launch rocket with countdown and acceleration in stdout}}
 
;Task Description:
Simulate the countdown of a rocket launch from   '''5'''   down to   '''0'''   seconds,   and then display the moving, accelerating rocket on the standard output device as a simple ASCII art animation.
<br><br>
 
=={{header|8080 Assembly}}==
The task is to simulate the countdown of a rocket launch from 5 down to 0 seconds and then display the moving, accelerating rocket on the standard output device as a simple ASCII art animation.
 
This program runs under CP/M. It assumes a terminal that understands the
ASCII CR, LF, and FF control codes (in practice this will be all of them).
If your machine has blinkenlights (e.g. an Altair 8800), the top half of the address bus
will additionally show a countdown going from 5 to 0 lights.
 
The 8080 is assumed to be clocked at 2 Mhz, which was the rated maximum
for the earlier chips. If you overclock your Altair, or run this program on a later Z80-based machine,
the countdown will go faster. In a non-cycle-accurate emulator, the program will run in an instant.
In SIMH, the command <code>d clock 2000</code> might help.
 
<syntaxhighlight lang="8080asm"> org 100h
lxi d,rocket ; Clear screen and print rocket
mvi c,9
call 5
mvi a,0F8h ; Five lights
lxi h,number
cdwn: lxi d,count ; Print countdown
call sout
call sec ; Wait a second
dcr m ; Decrease number
add a ; Turn off a light
jnz cdwn ; Again (if not zero yet)
lxi d,flame ; Print flame
call sout
mvi c,24 ; Lines
lxi h,20000 ; Liftoff timer
lift: lxi d,newln
call sout
call waithl
lxi d,-800
dad d
dcr c
jnz lift
ret
sout: push psw ; Print string [DE] preserving registers
push b
push h
mvi c,9
call 5
jmp rsto
;;; Busy wait counting down HL.
;;; 52 + 24*HL cycles = 26 + 12*HL nanoseconds
waithl: push psw ; 11 cycles
push h ; 11 cycles
spin: dcx h ; 5 cycles ----
mov a,h ; 5 cycles
ora l ; 4 cycles loop
jnz spin ; 10 cycles ----
pop h ; 10 cycles
pop psw ; 10 cycles
ret ; 10 cycles
;;; Busy wait approximately one second (assuming 2Mhz clock)
;;; Pattern in A on address bus (will appear on blinkenlights
;;; if there are any).
sec: push psw
push b
push h
mov b,a ; Set up for pattern
lxi h,25000 ; 25.000 * 80 = 2.000.000 cycles ~= 1 sec
swait: ldax b ; 56 cycles, and hold pattern on blinkenlights
ldax b ; ...
ldax b
ldax b
ldax b
ldax b
ldax b
ldax b
dcx h ; 5 cycles
mov a,h ; 5 cycles
ora l ; 4 cycles
jnz swait ; 10 cycles
rsto: pop h
pop b
pop psw
ret
;;; Rocket
rocket: db 12, 10,10,10,10,10, 10,10,10,10,10
db ' |',13,10
db ' / ',92,13,10
db ' / _ ',92,13,10
db ' |.o ',39,'.|',13,10
db ' |',39,'._.',39,'|',13,10
db ' | |',13,10
db ' ,',39,'| | |`.',13,10
db ' / | | | ',92,13,10
db ' |,-',39,'--|--',39,'-.|' ,13,10,'$'
flame: db ' ******* ',13,10
db ' .*****.',13,10
db ' .***.',13,10
db ' .*.',13,10
db ' .',13,10,'$'
count: db ' _____ '
number: db '5 _____',13,'$'
newln: db 13,10,'$'</syntaxhighlight>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">#define sky 32
dim as string rocket(1 to 7) = { " ^",_
" / " + chr(92),_
" | |",_
" | H |",_
" | |",_
" /|/ \|" + chr(92),_
"/_||.||_" + chr(92) }
 
dim as double h = 0, dhdt = 0, d2hdt2 = 0.3, t, countdown = 5, dt
dim as integer ih, j, cut, lines
cls
while countdown > 0
t = timer
print countdown,
while timer < t + 1
wend
countdown -= 1
wend
cls
 
while h < sky
lines = 0
t = timer
ih = int(h)
for j = 1 to sky - 7 - h
lines += 1
print
next j
if ih < sky - 7 then cut = 6 else cut = sky - ih - 1
for j = 7-cut to 7
lines += 1
print rocket(j)
next j
for j = sky-ih+1 to sky
lines += 1
print " *** "
next j
if lines < sky then print " ***"
print "-------------------"
h += dhdt * dt
dhdt += d2hdt2 * dt
while t + 1./30 > timer
wend
cls
dt = timer - t
wend</syntaxhighlight>
 
=={{header|Go}}==
Line 12 ⟶ 155:
<br>
...though my rocket is a bit fancier :)
<langsyntaxhighlight lang="go">package main
 
import (
Line 65 ⟶ 208:
}
}
}</langsyntaxhighlight>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">rocket() = println(" /..\\\n |==|\n | |\n | |\n",
" | |\n /____\\\n | |\n |SATU|\n | |\n",
" | |\n /| | |\\\n / | | | \\\n /__|_|__|__\\\n /_\\/_\\\n")
 
exhaust() = println(" *****")
cls() = print("\x1B[2J")
curup(n) = print("\e[$(n)A")
curdown(n) = print("\e[$(n)B")
 
function countdown(secs)
print("Countdown...T minus ")
for i in secs:-1:1
print(i, "... ")
sleep(1)
end
print("LIFTOFF!")
end
 
engineburn(rows) = (println("\n"); for i in 1:rows exhaust(); sleep(0.9^i); end)
 
testrocket() = (cls(); rocket(); curup(16); countdown(5); curdown(13); engineburn(30))
 
testrocket()
</syntaxhighlight>{{out}}
<pre>
Countdown...T minus 5... 4... 3...
/..\
|==|
| |
| |
| |
/____\
| |
|SATU|
| |
| |
/| | |\
/ | | | \
/__|_|__|__\
/_\/_\
</pre>
 
=={{header|Nim}}==
{{trans|Julia}}
Using <code>terminal</code> module from standard library rather the escape codes.
<syntaxhighlight lang="nim">import os, math, terminal
 
proc rocket() =
echo " /..\\\n |==|\n | |\n | |\n",
" | |\n /____\\\n | |\n |SATU|\n | |\n",
" | |\n /| | |\\\n / | | | \\\n /__|_|__|__\\\n /_\\/_\\\n"
 
proc exhaust() =
echo " *****"
 
proc countDown(secs: Natural) =
stdout.write "Countdown...T minus "
stdout.flushFile
for i in countdown(secs, 1):
stdout.write i, "... "
stdout.flushFile
os.sleep(1000)
stdout.write "LIFTOFF!"
stdout.flushFile
 
proc engineBurn(rows: Natural) =
echo '\n'
for i in 1..rows:
exhaust()
sleep (0.9^i * 1000).toInt
 
proc testRocket() =
eraseScreen()
rocket()
cursorUp(16)
countDown(5)
cursorDown(13)
engineBurn(30)
 
testRocket()</syntaxhighlight>
 
{{out}}
Same as Julia program output.
 
=={{header|Pascal}}==
Pascal includes the standard routine <tt>page</tt>.
However its specific behavior is implementation-defined, i. e. up to the compiler vendor.
''An'' implementation of <tt>page</tt> ''could'', for instance, translate into <tt>\014</tt> (ASCII form feed) or <tt>\033[2J\033[H</tt>, the ANSI escape sequence blanking the entire screen and moving the cursor to the upper left-hand corner.
If the terminal interprets them properly, the following <tt>program</tt> could satisfy the task’s requirements:
<syntaxhighlight lang="pascal">program launchRocketWithCountdownAndAccelerationOnOutput(output);
 
const
screenWidth = 80;
 
type
wholeNumber = 0..maxInt;
natural = 1..maxInt;
 
var
n: wholeNumber;
 
{
Pascal, as defined by ISO standard 7185, does not provide any
facilities to time actions. Nevertheless, most compiler vendors
invented their own `sleep` or `delay` procedures.
}
procedure sleep(n: natural);
begin
{ Yes, in Pascal an empty statement is valid. }
{ There is really nothing after `do`. }
for n := n downto 1 do
end;
 
procedure drawRocket(column: natural);
begin
{ `page` is shorthand for `page(output)`, }
{ as is `writeLn(…)` shorthand for `writeLn(output, …)`. }
page;
{ It should be an easy feat to adapt this to contain ASCII only. }
writeLn(' ':column, '🙮')
end;
 
{ === MAIN ============================================================= }
begin
for n := 5 downto 0 do
begin
drawRocket(1);
writeLn;
writeLn(n);
sleep(5318008)
end;
n := 1;
while n < screenWidth do
begin
n := round(n * 1.5);
sleep(58008);
drawRocket(n)
end
end.</syntaxhighlight>Note, conventionally main engines (liquid fuel) are ignited a few seconds prior liftoff and SRBs are ignited just at/before liftoff, so the graphical depiction of exhaust visible at T−5 is ''about'' accurate.
 
=={{header|Perl}}==
{{trans|Raku}}
<syntaxhighlight lang="perl">use strict;
use warnings;
use Time::HiRes qw(sleep);
 
$SIG{INT} = \&clean_up;
 
my ($rows,$cols) = split /\s+/, qx/stty size/;
my $v = $rows - 9;
my $h = int $cols / 2 - 4;
my $a = 0;
my $i = 0;
my $j = 0;
my $t = -5;
my $start = $^T;
 
my @r = (q' |', q' /_\\', q' | |', q' /| |\\', q'/_|_|_\\');
my @x = (q' (/|\\)', q' {/|\\}', q' \\|/', q' |');
my @y = (q' /|\\', q' // \\\\', q' (/ \\)', q' \\ /');
 
my $sp = ' ' x $h;
 
my $altitude = 0;
my $velocity = 0;
 
my @pal = ("\e[38;2;255;0;0m", "\e[38;2;255;255;0m", "\e[38;2;255;155;0m");
use constant W => "\e[38;2;255;255;255m";
 
print "\e[?25l\e[48;5;232m";
 
while (1) {
if ($t >= 0) {
$velocity = 5 * $t**2;
$altitude = $velocity * $t / 2;
$a = int 0.5 + ($altitude / $v);
}
clean_up() if $a > $rows + 5;
 
print "\e[H\e[J", ("\n")x$v, W, $sp, join("\n$sp",@r), "\n", $sp;
 
if ($t < 0) {
print q'\\/ \\/'
} else {
exhaust( $pal[$i], $a )
}
print W, "\n", '▔' x $cols, $pal[1];
printf "\n Time: T %-4s %9s Altitude: %6.2f meters Velocity: %5.1f m/sec\n",
$t < 0 ? '- ' . int 0.5 + abs $t : '+ ' . int 0.5 + $t,
$t < 0 ? '' : $a == 0 ? 'Ignition!' : 'Lift-off!',
sprintf('%.2f', $altitude), sprintf('%.1f', $velocity);
 
++$i;
$i %= 3;
++$j;
$j %= 2;
$t = (time() - $start - 5);
sleep .05;
}
 
sub exhaust {
my($clr, $a) = @_;
print q'\\/', $clr, q'/^\\', W, q'\\/';
return if $a == 0;
if ($a < 4) {
print "\n", $clr,
$sp, ( $j ? join("\n$sp", @x[0..$a-1]) : join("\n$sp", @y[0..$a-1]) )
} else {
print "\n", $clr,
$sp, ( $j ? join("\n$sp",@x) : join("\n$sp",@y) );
print "\n" x ($a-4);
}
}
 
# clean up on exit, reset ANSI codes, scroll, re-show the cursor & clear screen
sub clean_up { print "\e[0m", ("\n")x50, "\e[H\e[J\e[?25h"; exit(0) }</syntaxhighlight>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">-->
<span style="color: #004080;">sequence</span> <span style="color: #000000;">rocket</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"""
/\
/ \
| |
| |
/|/\|\
/_||||_\
"""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">10</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0.25</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rocket</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">></span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">rocket</span><span style="color: #0000FF;">[$]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"T minus %d... "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">t</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">-- allow console resize during countdown:</span>
<span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">video_config</span><span style="color: #0000FF;">()[</span><span style="color: #004600;">VC_SCRNLINES</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">-</span><span style="color: #000000;">7</span> <span style="color: #008080;">then</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">else</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">rocket</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">rocket</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$]</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">l</span> <span style="color: #0000FF;">-=</span> <span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rocket</span><span style="color: #0000FF;">)></span><span style="color: #000000;">6</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rocket</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">12</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">rocket</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rocket</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" ** "</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rocket</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">12</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">rocket</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rocket</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">*=</span> <span style="color: #000000;">0.95</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">clear_screen</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">cursor</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NO_CURSOR</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">lines</span><span style="color: #0000FF;">-</span><span style="color: #000000;">7</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">position</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rocket</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">sleep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">t</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000000;">rocket</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">rocket</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..$-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">cursor</span><span style="color: #0000FF;">(</span><span style="color: #004600;">BLOCK_CURSOR</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
 
=={{header|Racket}}==
 
{{trans|Go}}
 
<syntaxhighlight lang="racket">#lang racket
 
(define rocket #<<EOF
/\
( )
( )
/|/\|\
/_||||_\
EOF
)
 
(define (cls) (displayln "\x1B[2J"))
 
(define (print-rocket n)
(displayln rocket)
(for ([i (in-range n)]) (displayln "")))
 
(for ([i (in-range 5 0 -1)])
(cls)
(printf "~a =>\n" i)
(print-rocket 0)
(sleep 1))
 
(cls)
(printf "Liftoff!\n")
(print-rocket 1)
(sleep 1)
 
(for/fold ([ms 1000] #:result (void)) ([n (in-range 2 100)])
(cls)
(print-rocket n)
(sleep (/ ms 1000))
(if (>= ms 40) (- ms 40) 0))</syntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2019.07.1}}
Uses ANSI graphics. Works best in a 24 bit ANSI terminal at least 80x24, though bigger is better.
 
This is a very simple simulation. It assumes a constant ~2G+ acceleration in a gravitational field; so net +10 meters per second². It completely neglects the effects of [[wp:Drag_(physics)|air friction]], [[wp:Impulse|impulse]], [[wp:Snap,_Crackle_and_Pop#Physics|snap, crackle & pop]] and has an unrealistically clean fuel burn (no contrail). It does however (unlike most of the entries at this time) start at the base of the terminal (on the ground) and go up, rather than starting at the top and dropping a contrail. It calculates and displays an accurate displacement and velocity over time and uses those to scale its vertical screen displacement.
 
The motion is a little "notchy" as the vertical resolution in a terminal is rather low. Exits after the rocket leaves the visible area of the terminal. See the [https://github.com/thundergnat/rc/blob/master/img/rocket-perl6.gif example animated gif]
 
<syntaxhighlight lang="raku" line>signal(SIGINT).tap: { cleanup() }
 
my ($rows,$cols) = qx/stty size/.words;
my $v = floor $rows - 9;
my $h = floor $cols / 2 - 4;
my $a = 0;
my $start = now;
my $t = -5;
my $i = 0;
my $j = 0;
 
my @r = Q' |', Q' /_\', Q' | |', Q' /| |\', Q'/_|_|_\';
my @x = Q' (/|\)', Q' {/|\}', Q' \|/', Q' |';
my @y = Q' /|\', Q' // \\', Q' (/ \)', Q' \ /'; #'
 
my $sp = ' ' x $h;
 
my $altitude = 0;
my $velocity = 0;
 
my @pal = "\e[38;2;255;0;0m", "\e[38;2;255;255;0m", "\e[38;2;255;155;0m";
constant \W = "\e[38;2;255;255;255m";
 
print "\e[?25l\e[48;5;232m";
 
loop {
if $t >= 0 {
$velocity = 5 * $t²;
$altitude = $velocity * $t / 2;
$a = ($altitude / $v).round;
}
cleanup() if $a > $rows + 5;
 
print "\e[H\e[J", "\n" xx $v, W, $sp, @r.join("\n$sp"), "\n", $sp;
if $t < 0 {
print Q'\/ \/'
} else {
exhaust( @pal[$i], $a )
}
print W, "\n", '▔' x $cols, @pal[1];
printf "\n Time: T %-4s %9s Altitude: %6.2f meters Velocity: %5.1f m/sec\n",
$t < 0 ?? "- {$t.round.abs}" !! "+ {$t.round}",
$t < 0 ?? '' !! $a == 0 ?? 'Ignition!' !! 'Lift-off!',
$altitude.round(.01), $velocity.round(.1);
 
++$i;
$i %= 3;
++$j;
$j %= 2;
$t = (now - $start - 5);
sleep .05;
}
 
sub exhaust ($clr, $a) {
print Q'\/', $clr, Q'/^\', W, Q'\/'; #'
return if $a == 0;
if $a < 4 {
print "\n", $clr,
$sp, ( $j ?? @x[^$a].join("\n$sp") !! @y[^$a].join("\n$sp"))
} else {
print "\n", $clr,
$sp, ( $j ?? @x.join("\n$sp") !! @y.join("\n$sp"));
print "\n" x $a - 4;
}
}
 
# clean up on exit, reset ANSI codes, scroll, re-show the cursor & clear screen
sub cleanup () { print "\e[0m", "\n" xx 50, "\e[H\e[J\e[?25h"; exit(0) }</syntaxhighlight>
 
{{out|Sample output}}
See [https://github.com/thundergnat/rc/blob/master/img/rocket-perl6.gif rocket-perl6.gif] (offsite animated gif image)
 
=={{header|REXX}}==
This REXX program hard-codes the name of the (OS) command to clear the terminal screen &nbsp; ('''CLS''').
<lang rexx>/*REXX pgm does a countdown and then display the launching of a rocket (ASCII animation)*/
<syntaxhighlight lang="rexx">/*REXX pgm does a countdown and then display the launching of a rocket (ASCII animation)*/
parse arg cntDown . /*obtain optional argument from the CL.*/
if cntDown=='' | cntDown=="," then cntDown= 5 /*Not specified? Then use the default.*/
Line 84 ⟶ 613:
parse value scrsize() with sd sw .
sw= sw - 1 /*usable screen width on some systems. */
sd= sd - 3 /* " " depth " " " */
air= sd - 1 - rs /*"amount" of sky above the rocket. */
say
Line 98 ⟶ 627:
cls /*use this command to clear the screen.*/
call sky /*display the sky above the rocket. */
period= 1
dt= period / sd /*acceleration (period is decreasing).*/
call rocket /*display the rocket (in flight). */
do sd+4; say say /*"make" the rocket appear to fly. */
period= call delay .1 format(period-period*dt,,3) /*waitcalculate forthe one-tenthdecrease ofin athe secondperiod. */
call delay max(period, .001) end /*sd+4wait for a diminishing time interval.*/
end /*sd+4*/
exit /*stick a fork in it, da rocket is gone*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
sky: do air; say; end /*air*/; return /*display the sky above the rocket. */
rocket: do ship=1 for rs; say left('', sw%2 - 5) @.ship; end /*ship*/; return</langsyntaxhighlight>
This REXX program makes use of &nbsp; '''SCRSIZE''' &nbsp; REXX program (or
BIF) which is used to determine the screen
<br>width and depth of the terminal (console). &nbsp; Some REXXes don't
have this BIF.
 
The &nbsp; '''SCRSIZE.REX''' &nbsp; REXX program is included
here &nbsp; ───► &nbsp; [[SCRSIZE.REX]]. <br><br>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
use std::{thread, time};
 
Line 152 ⟶ 691:
}
 
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="wren">import "timer" for Timer
 
var rocket = "
/\\
( )
( )
/|/\\|\\
/_||||_\\
"
 
var printRocket = Fn.new { |above|
System.write(rocket)
if (above == 0) return
for (i in 1..above) System.print(" ||")
}
 
var cls = Fn.new { System.write("\x1B[2J") }
 
// counting
for (n in 5..1) {
cls.call()
System.print("%(n) =>")
printRocket.call(0)
Timer.sleep(1000)
}
 
// ignition
cls.call()
System.print("Lifetoff !")
printRocket.call(1)
Timer.sleep(1000)
 
// liftoff
var ms = 1000
for (n in 2..99) {
cls.call()
printRocket.call(n)
Timer.sleep(ms)
ms = (ms >= 40) ? ms - 40 : 0
}</syntaxhighlight>
 
=={{header|zkl}}==
{{trans|Go}}
Uses ANSI terminal codes.
<syntaxhighlight lang="zkl">var [const] rocket=
#<<<
0'~
/\
( )
( )
/|/\|\
/_||||_\
~, flame=" **";
#<<<
fcn cls { print("\x1B[2J") }
fcn cursorUp(n) { print("\e[%dA".fmt(n)) }
fcn cursorDown(n){ print("\e[%dB".fmt(n)) }
fcn cursor2Col(n){ print("\e[%dG".fmt(n)) }
 
fcn __main__{
tall,tall := rocket.counts(), tall[tall.find("\n")+1];
cls(); print(rocket); cursorUp(tall);
 
// count down to ignition
print("T minus: ");
foreach n in ([5..1, -1]){ print(n," "); Atomic.sleep(1); }
print(" Liftoff !"); cursorDown(tall); cursor2Col(1);
// liftoff
ms:=1.0; // 1 sec
do(25){
println(flame); Atomic.sleep(ms);
ms=(ms - 0.04).max(0); // 40 milliseconds faster than last time
}
}</syntaxhighlight>
{{out}}
<pre>
T minus: 5 4 3 2 1 Liftoff !
/\
( )
( )
/|/\|\
/_||||_\
**
**
**
**
</pre>
9,476

edits