Launch rocket with countdown and acceleration in stdout

Revision as of 15:42, 5 August 2019 by PureFox (talk | contribs) (→‎{{header|Go}}: Removed a superfluous blank line.)

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.

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



Go

Translation of: Rust


...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>

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>