restructure: arrays and slices
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
# GOAL 4: Blinking the Separators
|
||||
|
||||
## Notes
|
||||
|
||||
* Note main.go file contains the solution of the previous step.
|
||||
* "solution" folder contains the solution for this step.
|
||||
|
||||
## Challenge Steps
|
||||
|
||||
Separators should be visible once in every two seconds.
|
||||
|
||||
### Example:
|
||||
|
||||
* 1st second: They're invisible
|
||||
* 2nd second: visible
|
||||
* 3rd second: invisible
|
||||
* 4th second: visible
|
||||
|
||||
### HINT
|
||||
|
||||
There are two ways to do this:
|
||||
|
||||
1. Manipulating the clock array directly (by adding/removing the separators)
|
||||
|
||||
2. Or: Deciding what placeholders to print when printing the clock
|
137
15-project-retro-led-clock/04-blinking-the-separators/main.go
Normal file
137
15-project-retro-led-clock/04-blinking-the-separators/main.go
Normal file
@ -0,0 +1,137 @@
|
||||
// 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/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/inancgumus/screen"
|
||||
)
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
screen.Clear()
|
||||
|
||||
for {
|
||||
screen.MoveTopLeft()
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
// 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/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/inancgumus/screen"
|
||||
)
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
screen.Clear()
|
||||
|
||||
for {
|
||||
screen.MoveTopLeft()
|
||||
|
||||
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 index, digit := range clock {
|
||||
// colon blink
|
||||
next := clock[index][line]
|
||||
if digit == colon && sec%2 == 0 {
|
||||
next = " "
|
||||
}
|
||||
fmt.Print(next, " ")
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user