Matrix/main.go

65 lines
1.5 KiB
Go
Raw Normal View History

2024-04-12 07:54:27 +00:00
package main
import (
2024-04-14 19:47:13 +00:00
"fmt"
2024-04-12 08:00:53 +00:00
"log"
"github.com/go-resty/resty/v2"
"github.com/joho/godotenv"
2024-04-12 07:54:27 +00:00
)
2024-04-14 19:47:13 +00:00
func output(_ *resty.Client, _ string, width, height int, arr [][]Cell) {
for i := 0; i < width; i++ {
for j := 0; j < height; j++ {
if arr[i][j].live {
2024-04-14 20:02:46 +00:00
fmt.Printf("*")
2024-04-14 19:47:13 +00:00
} else {
fmt.Printf(" ")
}
}
fmt.Printf("\n")
}
}
2024-04-12 07:54:27 +00:00
func main() {
2024-04-12 08:02:12 +00:00
// Load .env file if it exists
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file")
}
// Load env server data
2024-04-12 11:30:00 +00:00
url, width, height := loadMatrixData()
2024-04-12 08:14:17 +00:00
log.Printf("At '%s': %d x %d\n", url, width, height)
// Initialize resty client
client := resty.New()
2024-04-14 19:48:03 +00:00
// Run Game of Life
done := setup(func(c [][]Cell) {
output(client, url, width, height, c)
}, width, height, 5)
2024-04-12 12:13:21 +00:00
2024-04-14 19:48:03 +00:00
// Wait for user input to quit
var input string
fmt.Scanln(&input)
// Stop Game of Life, wait for routine
done <- true
<-done
2024-04-12 12:13:21 +00:00
2024-04-14 19:47:48 +00:00
// // Initialize custom matrix data
// col := Color{R: 255, G: 0, B: 255, Endpoint: COLOR}
// rct := Rectangle{X: 0, Y: 0, W: 10, H: 10, Endpoint: RECTANGLE}
//
// // Send request to remote server
// sendRequest(client, url, []interface{}{col, rct})
//
// // Initialize custom matrix data
// col = Color{R: 255, G: 255, B: 0, Endpoint: COLOR}
// rct = Rectangle{X: 15, Y: 15, W: 15, H: 15, Endpoint: RECTANGLE}
// upd := Update{Endpoint: UPDATE}
//
// // Send request to remote server
// sendRequest(client, url, []interface{}{col, rct, upd})
2024-04-12 07:54:27 +00:00
}