refactor: move challenge steps to markdown files for the led clock
This commit is contained in:
43
15-arrays-project-clock/01-printing-the-digits/README.md
Normal file
43
15-arrays-project-clock/01-printing-the-digits/README.md
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# GOAL 1: Printing the Digits
|
||||||
|
|
||||||
|
## Challenge Steps
|
||||||
|
|
||||||
|
1. Define a new placeholder type
|
||||||
|
|
||||||
|
2. Create the digits from "zero" to "nine"
|
||||||
|
|
||||||
|
You can use these characters for the clock:
|
||||||
|
|
||||||
|
```
|
||||||
|
Digit character : █
|
||||||
|
Separator character : ░
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Put them into the "digits" array
|
||||||
|
|
||||||
|
2. Print the digits side-by-side
|
||||||
|
|
||||||
|
1. Loop for all the lines in a digit
|
||||||
|
|
||||||
|
2. Print each digit line by line
|
||||||
|
|
||||||
|
3. Don't forget printing a space after each digit
|
||||||
|
|
||||||
|
4. Don't forget printing a newline after each line
|
||||||
|
|
||||||
|
EXAMPLE: Let's say you want to print 10.
|
||||||
|
|
||||||
|
```
|
||||||
|
██ ███ <--- Print a new line after printing a single line from
|
||||||
|
█ █ █ all the digits.
|
||||||
|
█ █ █
|
||||||
|
█ █ █
|
||||||
|
███ ███
|
||||||
|
^^
|
||||||
|
||
|
||||||
|
++----> Add space between the digits
|
||||||
|
```
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
You can find the solution in the solution folder.
|
@ -7,41 +7,5 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
||||||
// ★ GOAL 1 : Printing the Digits
|
|
||||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
||||||
//
|
|
||||||
// 1. Define a new placeholder type
|
|
||||||
//
|
|
||||||
// 2. Create the digits from "zero" to "nine"
|
|
||||||
//
|
|
||||||
// You can use these characters for the clock:
|
|
||||||
//
|
|
||||||
// Digit character : "█"
|
|
||||||
// Separator character : "░"
|
|
||||||
//
|
|
||||||
// 3. Put them into the "digits" array
|
|
||||||
//
|
|
||||||
// 4. Print the digits side-by-side
|
|
||||||
//
|
|
||||||
// 1. Loop for all the lines in a digit
|
|
||||||
//
|
|
||||||
// 2. Print each digit line by line
|
|
||||||
//
|
|
||||||
// 3. Don't forget printing a space after each digit
|
|
||||||
//
|
|
||||||
// 4. Don't forget printing a newline after each line
|
|
||||||
//
|
|
||||||
// EXAMPLE: Let's say you want to print 10.
|
|
||||||
//
|
|
||||||
// ██ ███ <--- Print a new line after printing a single line from
|
|
||||||
// █ █ █ all the digits.
|
|
||||||
// █ █ █
|
|
||||||
// █ █ █
|
|
||||||
// ███ ███
|
|
||||||
// ^^
|
|
||||||
// ||
|
|
||||||
// ++----> Add space between the digits
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
}
|
}
|
||||||
|
20
15-arrays-project-clock/02-printing-the-clock/README.md
Normal file
20
15-arrays-project-clock/02-printing-the-clock/README.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# GOAL 2: Printing the Clock
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
* Note main.go file contains the solution of the previous step.
|
||||||
|
* "solution" folder contains the solution for this step.
|
||||||
|
|
||||||
|
## Challenge Steps
|
||||||
|
|
||||||
|
1. Get the current time
|
||||||
|
|
||||||
|
2. Get the current hour, minute and second from the current time
|
||||||
|
|
||||||
|
3. Create the clock array by getting the digits from the digits array
|
||||||
|
|
||||||
|
4. Print the clock by using the clock array
|
||||||
|
|
||||||
|
5. Create a separator array (it's also a placeholder type)
|
||||||
|
|
||||||
|
6. Add the separators into the correct positions of the clock array
|
@ -5,22 +5,6 @@
|
|||||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||||
//
|
//
|
||||||
|
|
||||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
||||||
// ★ GOAL 2 : Printing the Clock
|
|
||||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
||||||
//
|
|
||||||
// 1. Get the current time
|
|
||||||
//
|
|
||||||
// 2. Get the current hour, minute and second from the current time
|
|
||||||
//
|
|
||||||
// 3. Create the clock array by getting the digits from the digits array
|
|
||||||
//
|
|
||||||
// 4. Print the clock by using the clock array
|
|
||||||
//
|
|
||||||
// 5. Create a separator array (it's also a placeholder type)
|
|
||||||
//
|
|
||||||
// 6. Add the separators into the correct positions of the clock array
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
56
15-arrays-project-clock/03-animating-the-clock/README.md
Normal file
56
15-arrays-project-clock/03-animating-the-clock/README.md
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# GOAL 3: Animate the Clock
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
* Note main.go file contains the solution of the previous step.
|
||||||
|
* "solution" folder contains the solution for this step.
|
||||||
|
|
||||||
|
## Challenge Steps
|
||||||
|
|
||||||
|
1. Create an infinite loop to update the clock
|
||||||
|
|
||||||
|
2. Update the clock every second
|
||||||
|
|
||||||
|
[time.Sleep(time.Second)](https://golang.org/pkg/time/#Sleep) will stop the world for 1 second
|
||||||
|
|
||||||
|
3. Clear the screen before the infinite loop
|
||||||
|
|
||||||
|
1. Get my library for clearing the screen:
|
||||||
|
|
||||||
|
`go get -u github.com/inancgumus/screen`
|
||||||
|
|
||||||
|
2. Then, import it and call it in your code like this:
|
||||||
|
|
||||||
|
`screen.Clear()`
|
||||||
|
|
||||||
|
3. If you're using Go Playground instead, do this:
|
||||||
|
|
||||||
|
`fmt.Println("\f")`
|
||||||
|
|
||||||
|
4. Move the cursor to the top-left corner of the screen, before each step
|
||||||
|
of the infinite loop
|
||||||
|
|
||||||
|
* Call this in your code like this:
|
||||||
|
|
||||||
|
`screen.MoveTopLeft()`
|
||||||
|
|
||||||
|
* If you're using Go Playground instead, do this again:
|
||||||
|
|
||||||
|
`fmt.Println("\f")`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## SIDE NOTE FOR THE CURIOUS
|
||||||
|
|
||||||
|
If you're curious about how my screen clearing package works, read on.
|
||||||
|
|
||||||
|
**On bash**, it uses special commands, if you open the code, you can see that.
|
||||||
|
|
||||||
|
* `\033` is a special control code:
|
||||||
|
* `[2J` clears the screen and the cursor
|
||||||
|
* `[H` moves the cursor to 0, 0 screen position
|
||||||
|
* [See for more information](https://bluesock.org/~willkg/dev/ansi.html).
|
||||||
|
|
||||||
|
**On Windows**, I'm directly calling the Windows API functions. This is way advanced at this stage of the course, however, I'll probably explain it afterward.
|
||||||
|
|
||||||
|
So, my package automatically adjusts itself depending on where it is compiled. On Windows, it uses the special Windows API calls; On other operating systems, it uses the bash special commands that I've explained above.
|
@ -5,71 +5,6 @@
|
|||||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||||
//
|
//
|
||||||
|
|
||||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
||||||
// ★ GOAL 3 : Animate the Clock
|
|
||||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
||||||
|
|
||||||
// 1. Create an infinite loop to update the clock
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// 2. Update the clock every second
|
|
||||||
//
|
|
||||||
// time.Sleep(time.Second) will stop the world for 1 second
|
|
||||||
//
|
|
||||||
// See this for more info:
|
|
||||||
// https://golang.org/pkg/time/#Sleep
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// 3. Clear the screen before the infinite loop
|
|
||||||
//
|
|
||||||
// 1. Get my library for clearing the screen:
|
|
||||||
//
|
|
||||||
// go get -u github.com/inancgumus/screen
|
|
||||||
//
|
|
||||||
// 2. Then, import it and call it in your code like this:
|
|
||||||
//
|
|
||||||
// screen.Clear()
|
|
||||||
//
|
|
||||||
// 3. If you're using Go Playground instead, do this:
|
|
||||||
//
|
|
||||||
// fmt.Println("\f")
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// 1. Move the cursor to the top-left corner of the screen, before each step
|
|
||||||
// of the infinite loop
|
|
||||||
//
|
|
||||||
// + Call this in your code like this:
|
|
||||||
//
|
|
||||||
// screen.MoveTopLeft()
|
|
||||||
//
|
|
||||||
// + If you're using Go Playground instead, do this again:
|
|
||||||
//
|
|
||||||
// fmt.Println("\f")
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// SIDE NOTE FOR THE CURIOUS
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// If you're curious about how my screen clearing package works, read on.
|
|
||||||
//
|
|
||||||
// On bash, it uses special commands, if you open the code, you can see that.
|
|
||||||
//
|
|
||||||
// \033 is a special control code:
|
|
||||||
// [2J clears the screen and the cursor
|
|
||||||
// [H moves the cursor to 0, 0 screen position
|
|
||||||
//
|
|
||||||
// See for more info:
|
|
||||||
// https://bluesock.org/~willkg/dev/ansi.html
|
|
||||||
//
|
|
||||||
// On Windows, I'm directly calling the Windows API functions. This is way
|
|
||||||
// advanced at this stage of the course, however, I'll explain it afterward.
|
|
||||||
//
|
|
||||||
// My package automatically adjusts itself depending on where it is compiled.
|
|
||||||
// On Windows, it uses the special Windows API calls;
|
|
||||||
// On other operating systems, it uses the bash special commands
|
|
||||||
// that I've explained above.
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
25
15-arrays-project-clock/04-blinking-the-separators/README.md
Normal file
25
15-arrays-project-clock/04-blinking-the-separators/README.md
Normal file
@ -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
|
@ -5,34 +5,13 @@
|
|||||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||||
//
|
//
|
||||||
|
|
||||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
||||||
// ★ GOAL 4: Blinking the Separators
|
|
||||||
// ★★★★★★★★★★★★★★★★★★★★★★★★★★★
|
|
||||||
|
|
||||||
// They should be visible per two seconds.
|
|
||||||
//
|
|
||||||
// Example: 1st second invisible
|
|
||||||
// 2nd second visible
|
|
||||||
// 3rd second invisible
|
|
||||||
// 4th second visible
|
|
||||||
//
|
|
||||||
// HINT: There are two ways to do this.
|
|
||||||
//
|
|
||||||
// A- Manipulating the clock array directly
|
|
||||||
// (by adding/removing the separators)
|
|
||||||
//
|
|
||||||
// B- Deciding what placeholders to print when printing the clock
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
"github.com/inancgumus/screen"
|
||||||
screenClear = "\033[2J"
|
|
||||||
cursorMoveTop = "\033[H"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -130,10 +109,10 @@ func main() {
|
|||||||
zero, one, two, three, four, five, six, seven, eight, nine,
|
zero, one, two, three, four, five, six, seven, eight, nine,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print(screenClear)
|
screen.Clear()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fmt.Print(cursorMoveTop)
|
screen.MoveTopLeft()
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
hour, min, sec := now.Hour(), now.Minute(), now.Second()
|
hour, min, sec := now.Hour(), now.Minute(), now.Second()
|
||||||
|
Reference in New Issue
Block a user