Launch rocket with countdown and acceleration in stdout: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: Fix link: Perl 6 --> Raku) |
(add freebasic) |
||
Line 4: | Line 4: | ||
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. |
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. |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>#define sky 32 |
|||
dim as string rocket(1 to 7) = { " ^",_ |
|||
" / \",_ |
|||
" | |",_ |
|||
" | H |",_ |
|||
" | |",_ |
|||
" /|/ \|\",_ |
|||
"/_||.||_\" } |
|||
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</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |