mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-26 12:01:45 +00:00
simulate in console
This commit is contained in:
parent
27f84eca71
commit
93322ad555
13
main.go
13
main.go
@ -4,11 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/buger/goterm"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func output(client *resty.Client, url string, width, height int, arr [][]Cell) {
|
func output(client *resty.Client, url string, width, height int, arr [][]Cell) {
|
||||||
|
goterm.MoveCursor(0, 0)
|
||||||
// Prepare instructions for matrix
|
// Prepare instructions for matrix
|
||||||
instructions := make([]interface{}, 0)
|
instructions := make([]interface{}, 0)
|
||||||
// Append all live cells as pixel instructions
|
// Append all live cells as pixel instructions
|
||||||
@ -16,13 +18,20 @@ func output(client *resty.Client, url string, width, height int, arr [][]Cell) {
|
|||||||
for j := 0; j < height; j++ {
|
for j := 0; j < height; j++ {
|
||||||
if arr[i][j].live {
|
if arr[i][j].live {
|
||||||
instructions = append(instructions, Pixel{X: i, Y: j, Endpoint: PIXEL})
|
instructions = append(instructions, Pixel{X: i, Y: j, Endpoint: PIXEL})
|
||||||
|
goterm.Print("X")
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
goterm.Print(" ")
|
||||||
}
|
}
|
||||||
|
goterm.Println()
|
||||||
}
|
}
|
||||||
// Append update instruction
|
// Append update instruction
|
||||||
instructions = append(instructions, Update{Endpoint: UPDATE})
|
instructions = append(instructions, Update{Endpoint: UPDATE})
|
||||||
// Send to matrix
|
// Send to matrix
|
||||||
sendRequest(client, url, instructions)
|
sendRequest(client, url, instructions)
|
||||||
|
|
||||||
|
// Update terminal UI
|
||||||
|
goterm.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -36,6 +45,8 @@ func main() {
|
|||||||
url, width, height := loadMatrixData()
|
url, width, height := loadMatrixData()
|
||||||
log.Printf("At '%s': %d x %d\n", url, width, height)
|
log.Printf("At '%s': %d x %d\n", url, width, height)
|
||||||
|
|
||||||
|
// Initialize terminal UI
|
||||||
|
goterm.Clear()
|
||||||
// Initialize resty client
|
// Initialize resty client
|
||||||
client := resty.New()
|
client := resty.New()
|
||||||
// Initialize pixel color
|
// Initialize pixel color
|
||||||
@ -44,7 +55,7 @@ func main() {
|
|||||||
// Run Game of Life
|
// Run Game of Life
|
||||||
done := setup(func(c [][]Cell) {
|
done := setup(func(c [][]Cell) {
|
||||||
output(client, url, width, height, c)
|
output(client, url, width, height, c)
|
||||||
}, width, height, 5)
|
}, width, height, 10)
|
||||||
|
|
||||||
// Wait for user input to quit
|
// Wait for user input to quit
|
||||||
fmt.Scanln()
|
fmt.Scanln()
|
||||||
|
Loading…
Reference in New Issue
Block a user