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

Content added Content deleted
(Converted to a draft task and clarified task description a bit.)
(Added Go)
Line 5: Line 5:
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|Go}}==
{{trans|Rust}}
<br>
...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>


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