2018-11-17 21:56:09 +03:00
|
|
|
// For more tutorials: https://blog.learngoprogramming.com
|
|
|
|
//
|
|
|
|
// Copyright © 2018 Inanc Gumus
|
|
|
|
// Learn Go Programming Course
|
|
|
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
|
|
//
|
|
|
|
|
2018-12-06 23:20:51 +03:00
|
|
|
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
|
|
// ★ GOAL 4: Blinking the Separators
|
|
|
|
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
|
|
|
2018-12-15 13:34:39 +03:00
|
|
|
// They should be visible per two seconds.
|
2018-12-06 23:20:51 +03:00
|
|
|
//
|
|
|
|
// Example: 1st second invisible
|
|
|
|
// 2nd second visible
|
|
|
|
// 3rd second invisible
|
|
|
|
// 4th second visible
|
|
|
|
//
|
|
|
|
// HINT: There are two ways to do this.
|
|
|
|
//
|
2018-12-15 13:34:39 +03:00
|
|
|
// A- Manipulating the clock array directly
|
2018-12-06 23:20:51 +03:00
|
|
|
// (by adding/removing the separators)
|
|
|
|
//
|
2018-12-15 13:34:39 +03:00
|
|
|
// B- Deciding what placeholders to print when printing the clock
|
2018-12-06 23:20:51 +03:00
|
|
|
|
2018-11-17 21:56:09 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
screenClear = "\033[2J"
|
|
|
|
cursorMoveTop = "\033[H"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
type placeholder [5]string
|
|
|
|
|
|
|
|
zero := placeholder{
|
|
|
|
"███",
|
|
|
|
"█ █",
|
|
|
|
"█ █",
|
|
|
|
"█ █",
|
|
|
|
"███",
|
|
|
|
}
|
|
|
|
|
|
|
|
one := placeholder{
|
|
|
|
"██ ",
|
|
|
|
" █ ",
|
|
|
|
" █ ",
|
|
|
|
" █ ",
|
|
|
|
"███",
|
|
|
|
}
|
|
|
|
|
|
|
|
two := placeholder{
|
|
|
|
"███",
|
|
|
|
" █",
|
|
|
|
"███",
|
|
|
|
"█ ",
|
|
|
|
"███",
|
|
|
|
}
|
|
|
|
|
|
|
|
three := placeholder{
|
|
|
|
"███",
|
|
|
|
" █",
|
|
|
|
"███",
|
|
|
|
" █",
|
|
|
|
"███",
|
|
|
|
}
|
|
|
|
|
|
|
|
four := placeholder{
|
|
|
|
"█ █",
|
|
|
|
"█ █",
|
|
|
|
"███",
|
|
|
|
" █",
|
|
|
|
" █",
|
|
|
|
}
|
|
|
|
|
|
|
|
five := placeholder{
|
|
|
|
"███",
|
|
|
|
"█ ",
|
|
|
|
"███",
|
|
|
|
" █",
|
|
|
|
"███",
|
|
|
|
}
|
|
|
|
|
|
|
|
six := placeholder{
|
|
|
|
"███",
|
|
|
|
"█ ",
|
|
|
|
"███",
|
|
|
|
"█ █",
|
|
|
|
"███",
|
|
|
|
}
|
|
|
|
|
|
|
|
seven := placeholder{
|
|
|
|
"███",
|
|
|
|
" █",
|
|
|
|
" █",
|
|
|
|
" █",
|
|
|
|
" █",
|
|
|
|
}
|
|
|
|
|
|
|
|
eight := placeholder{
|
|
|
|
"███",
|
|
|
|
"█ █",
|
|
|
|
"███",
|
|
|
|
"█ █",
|
|
|
|
"███",
|
|
|
|
}
|
|
|
|
|
|
|
|
nine := placeholder{
|
|
|
|
"███",
|
|
|
|
"█ █",
|
|
|
|
"███",
|
|
|
|
" █",
|
|
|
|
"███",
|
|
|
|
}
|
|
|
|
|
|
|
|
colon := placeholder{
|
|
|
|
" ",
|
|
|
|
" ░ ",
|
|
|
|
" ",
|
|
|
|
" ░ ",
|
|
|
|
" ",
|
|
|
|
}
|
|
|
|
|
|
|
|
digits := [...]placeholder{
|
|
|
|
zero, one, two, three, four, five, six, seven, eight, nine,
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Print(screenClear)
|
|
|
|
|
|
|
|
for {
|
|
|
|
fmt.Print(cursorMoveTop)
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
hour, min, sec := now.Hour(), now.Minute(), now.Second()
|
|
|
|
|
|
|
|
clock := [...]placeholder{
|
|
|
|
digits[hour/10], digits[hour%10],
|
|
|
|
colon,
|
|
|
|
digits[min/10], digits[min%10],
|
|
|
|
colon,
|
|
|
|
digits[sec/10], digits[sec%10],
|
|
|
|
}
|
|
|
|
|
|
|
|
for line := range clock[0] {
|
|
|
|
for digit := range clock {
|
|
|
|
fmt.Print(clock[digit][line], " ")
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}
|