Map image generator
This commit is contained in:
53
examples/genmaps/util_funcs.go
Normal file
53
examples/genmaps/util_funcs.go
Normal file
@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/png"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func savePng(img image.Image, name string) {
|
||||
f, err := os.Create(name)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := png.Encode(f, img); err != nil {
|
||||
f.Close()
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := f.Close(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
//go:embed colors.gob
|
||||
var colorsBin []byte // gob([]color.RGBA64)
|
||||
|
||||
func init() {
|
||||
if err := gob.NewDecoder(bytes.NewReader(colorsBin)).Decode(&colors); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func usage() {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "usage: %s [-region <region path>] \n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func mkmax(c, n *int) {
|
||||
if *c < *n {
|
||||
*c = *n
|
||||
}
|
||||
}
|
||||
func mkmin(c, n *int) {
|
||||
if *c > *n {
|
||||
*c = *n
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user