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

From Rosetta Code
Content added Content deleted
 
(Converted to a draft task and clarified task description a bit.)
Line 1: Line 1:
{{draft task|Launch rocket with countdown and acceleration in stdout}}
===Task description===


;Task Description
You need to implement countdown of rocket launch from 5..0 seconds and then implement a moving rocket with a acceleration on standard output as 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.


===Solutions===


=={{header|Rust}}==
=={{header|Rust}}==

Revision as of 15:24, 5 August 2019

Launch rocket with countdown and acceleration in stdout is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
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.


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>