Skip to content

Instantly share code, notes, and snippets.

@tomlockwood

tomlockwood/main.go

Created Mar 28, 2020
Embed
What would you like to do?
gogol interface code
package main
import (
"fmt"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/kbinani/screenshot"
gol "github.com/tomlockwood/gogol"
render "github.com/tomlockwood/gogol/render"
"image"
"image/png"
"io/ioutil"
"os"
"time"
)
var screenCapture = false
var frameNumber = 1
var folderName = int64(0)
func test() {
if render.Reacted() {
if screenCapture {
topLeft := image.Point{0, 450}
bottomRight := image.Point{3000, 2000}
boundz := image.Rectangle{topLeft, bottomRight}
img, err := screenshot.CaptureRect(boundz)
if err != nil {
panic(err)
}
file, _ := os.Create(fmt.Sprintf("%d/%04d_screenshot.png", folderName, frameNumber))
png.Encode(file, img)
file.Close()
frameNumber++
}
} else if render.ActionKey() == glfw.KeyEscape {
render.CloseScreen()
} else if render.ActionKey() == glfw.KeyR {
g := render.GetGame()
g.Reset()
render.SetGame(g)
} else if render.ActionKey() == glfw.KeyC {
screenCapture = !screenCapture
if screenCapture {
frameNumber = 1
folderName = time.Now().UnixNano()
errDir := os.MkdirAll(fmt.Sprintf("%d", folderName), 0755)
if errDir != nil {
panic(errDir)
}
}
}
render.Acted()
}
func main() {
files, err := ioutil.ReadDir(".")
if err != nil {
return
}
renderer := render.Make(3840, 2160, 60)
var r0 = gol.Rule{
Alive: false,
Transitions: [9]uint8{0, 0, 0, 1, 0, 0, 0, 0, 0},
Colour: gol.Colour{R: 255.0, G: 255.0, B: 255.0}}
var r1 = gol.Rule{
Alive: true,
Transitions: [9]uint8{0, 0, 1, 1, 0, 0, 0, 0, 0},
Colour: gol.Colour{R: 0.0, G: 0.0, B: 0.0}}
var rs = gol.Rules{Array: []gol.Rule{r0, r1}}
gameopts := gol.Options{
X: 160, Y: 90, Grid: [][]uint8{},
RuleNumber: 2, Rules: rs}
render.InitGame(gameopts)
g := render.GetGame()
g.Reset()
render.SetGame(g)
render.SetActionFunction(test)
renderer.Render()
for _, file := range files {
if file.Name()[len(file.Name())-4:] == "json" {
gameopts = gol.Load(file.Name())
println(file.Name())
render.InitGame(gameopts)
render.SetActionFunction(test)
renderer.Render()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.