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

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎Pascal: add some explanation)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(One intermediate revision by one other user not shown)
Line 17:
In SIMH, the command <code>d clock 2000</code> might help.
 
<langsyntaxhighlight lang="8080asm"> org 100h
lxi d,rocket ; Clear screen and print rocket
mvi c,9
Line 100:
count: db ' _____ '
number: db '5 _____',13,'$'
newln: db 13,10,'$'</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">#define sky 32
dim as string rocket(1 to 7) = { " ^",_
" / " + chr(92),_
Line 149:
cls
dt = timer - t
wend</langsyntaxhighlight>
 
=={{header|Go}}==
Line 155:
<br>
...though my rocket is a bit fancier :)
<langsyntaxhighlight lang="go">package main
 
import (
Line 208:
}
}
}</langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">rocket() = println(" /..\\\n |==|\n | |\n | |\n",
" | |\n /____\\\n | |\n |SATU|\n | |\n",
" | |\n /| | |\\\n / | | | \\\n /__|_|__|__\\\n /_\\/_\\\n")
Line 234:
 
testrocket()
</langsyntaxhighlight>{{out}}
<pre>
Countdown...T minus 5... 4... 3...
Line 256:
{{trans|Julia}}
Using <code>terminal</code> module from standard library rather the escape codes.
<langsyntaxhighlight Nimlang="nim">import os, math, terminal
 
proc rocket() =
Line 290:
engineBurn(30)
 
testRocket()</langsyntaxhighlight>
 
{{out}}
Line 300:
''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:
<langsyntaxhighlight lang="pascal">program launchRocketWithCountdownAndAccelerationOnOutput(output);
 
const
Line 350:
drawRocket(n)
end
end.</langsyntaxhighlight>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}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use Time::HiRes qw(sleep);
Line 427:
 
# 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) }</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="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;">"""
/\
Line 474:
<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>
<!--</langsyntaxhighlight>-->
 
=={{header|Racket}}==
Line 480:
{{trans|Go}}
 
<langsyntaxhighlight lang="racket">#lang racket
 
(define rocket #<<EOF
Line 512:
(print-rocket n)
(sleep (/ ms 1000))
(if (>= ms 40) (- ms 40) 0))</langsyntaxhighlight>
 
=={{header|Raku}}==
Line 523:
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" perl6line>signal(SIGINT).tap: { cleanup() }
 
my ($rows,$cols) = qx/stty size/.words;
Line 590:
 
# 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) }</langsyntaxhighlight>
 
{{out|Sample output}}
Line 597:
=={{header|REXX}}==
This REXX program hard-codes the name of the (OS) command to clear the terminal screen &nbsp; ('''CLS''').
<langsyntaxhighlight 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 637:
/*──────────────────────────────────────────────────────────────────────────────────────*/
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
Line 647:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
use std::{thread, time};
 
Line 691:
}
 
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
{{trans|Go}}
<langsyntaxhighlight ecmascriptlang="wren">import "timer" for Timer
 
var rocket = "
Line 734:
Timer.sleep(ms)
ms = (ms >= 40) ? ms - 40 : 0
}</langsyntaxhighlight>
 
=={{header|zkl}}==
{{trans|Go}}
Uses ANSI terminal codes.
<langsyntaxhighlight lang="zkl">var [const] rocket=
#<<<
0'~
Line 770:
ms=(ms - 0.04).max(0); // 40 milliseconds faster than last time
}
}</langsyntaxhighlight>
{{out}}
<pre>
9,476

edits