Launch rocket with countdown and acceleration in stdout: Difference between revisions
m (→{{header|Go}}: Removed a superfluous blank line.) |
(→{{header|REXX}}: added the REXX computer programming language for this task.) |
||
Line 66: | Line 66: | ||
} |
} |
||
}</lang> |
}</lang> |
||
=={{header|REXX}}== |
|||
<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.*/ |
|||
@. = /* [↓] glyphs for the rocket ship. */ |
|||
@.1= ' /\ ' |
|||
@.2= ' | | ' |
|||
@.3= ' | | ' |
|||
@.4= ' | | ' |
|||
@.5= ' /|/\|\ ' |
|||
@.6= '/_||||_\' |
|||
do rs=1 while @.rs\=='' /*determine size of the rocket (height)*/ |
|||
end /*rs*/ |
|||
rs= rs - 1 /*the true rocket size (height). */ |
|||
cls= 'CLS' /*the command used to clear the screen.*/ |
|||
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 |
|||
do j=cntDown by -1 to 1 /* [↓] perform countdown; show rocket.*/ |
|||
cls /*use this command to clear the screen.*/ |
|||
say right(j, 9) 'seconds' /*display the amount of seconds to go. */ |
|||
call sky /*display the sky above the rocket. */ |
|||
call rocket /*display the rocket (on the ground). */ |
|||
call delay 1 /*wait one second during the countdown.*/ |
|||
end /*j*/ |
|||
say left('',9) "liftoff!" /*announce liftoff of the rocket. */ |
|||
cls /*use this command to clear the screen.*/ |
|||
call sky /*display the sky above the rocket. */ |
|||
call rocket /*display the rocket (in flight). */ |
|||
do sd+4; say /*"make" the rocket appear to fly. */ |
|||
call delay .1 /*wait for one-tenth of a second. */ |
|||
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</lang> |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |
Revision as of 23:10, 5 August 2019
- Task Description
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.
Go
...though my rocket is a bit fancier :)
<lang go>package main
import (
"fmt" "time"
)
const rocket = `
/\ ( ) ( ) /|/\|\ /_||||_\
`
func printRocket(above int) {
fmt.Print(rocket) for i := 1; i <= above; i++ { fmt.Println(" ||") }
}
func cls() {
fmt.Print("\x1B[2J")
}
func main() {
// counting for n := 5; n >= 1; n-- { cls() fmt.Printf("%d =>\n", n) printRocket(0) time.Sleep(time.Second) }
// ignition cls() fmt.Println("Liftoff !") printRocket(1) time.Sleep(time.Second)
// liftoff ms := time.Duration(1000) for n := 2; n < 100; n++ { cls() printRocket(n) time.Sleep(ms * time.Millisecond) if ms >= 40 { ms -= 40 } else { ms = 0 } }
}</lang>
REXX
<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.*/
@. = /* [↓] glyphs for the rocket ship. */ @.1= ' /\ ' @.2= ' | | ' @.3= ' | | ' @.4= ' | | ' @.5= ' /|/\|\ ' @.6= '/_||||_\' do rs=1 while @.rs\== /*determine size of the rocket (height)*/ end /*rs*/
rs= rs - 1 /*the true rocket size (height). */ cls= 'CLS' /*the command used to clear the screen.*/ 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
do j=cntDown by -1 to 1 /* [↓] perform countdown; show rocket.*/ cls /*use this command to clear the screen.*/ say right(j, 9) 'seconds' /*display the amount of seconds to go. */ call sky /*display the sky above the rocket. */ call rocket /*display the rocket (on the ground). */ call delay 1 /*wait one second during the countdown.*/ end /*j*/
say left(,9) "liftoff!" /*announce liftoff of the rocket. */ cls /*use this command to clear the screen.*/ call sky /*display the sky above the rocket. */ call rocket /*display the rocket (in flight). */
do sd+4; say /*"make" the rocket appear to fly. */ call delay .1 /*wait for one-tenth of a second. */ 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</lang>
Rust
<lang rust> use std::{thread, time};
fn print_rocket(above: u32) { print!( " oo
oooo oooo oooo
"); for _num in 1..above+1 {
println!(" ||");
} }
fn main() {
// counting for number in (1..6).rev() { print!("\x1B[2J"); println!("{} =>", number); print_rocket(0);
let dur = time::Duration::from_millis(1000);
thread::sleep(dur); }
// ignition print!("\x1B[2J"); println!("Liftoff !"); print_rocket(1); let dur = time::Duration::from_millis(1000); thread::sleep(dur);
// liftoff let mut dur_time : u64 = 1000; for number in 2..100 { print!("\x1B[2J"); print_rocket(number);
let dur = time::Duration::from_millis(dur_time);
thread::sleep(dur);
dur_time -= if dur_time >= 30 {30} else {dur_time};
}
}
</lang>