Init commit

This commit is contained in:
2025-02-11 22:30:13 +01:00
commit 495a7cce20
6 changed files with 213 additions and 0 deletions

54
cmd/gol/gol.go Normal file
View File

@ -0,0 +1,54 @@
package main
import (
"gol/gol"
"gol/term"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
front := gol.New(20, 40)
back := gol.New(20, 40)
// glider
front[0][3] = true
front[1][4] = true
front[2][2] = true
front[2][3] = true
front[2][4] = true
// cross
front[16][21] = true
front[17][21] = true
front[18][21] = true
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
term.StartFullscreen()
term.TurnCursor(term.CursorOff)
loop := func() {
ticker := time.NewTicker(250 * time.Millisecond)
for {
term.GoHome()
front.PrintMe()
front.NextGen(back)
front, back = back, front
select {
case <-sigs: // przerwanie
return
case <-ticker.C: // upłynął czas do kolejnej generacji
}
}
}
defer func() {
term.FinishFullscreen()
term.TurnCursor(term.CursorOn)
}()
loop()
}