removed invert option, added new standard theme (orange on grey)

This commit is contained in:
2024-06-08 16:19:54 +02:00
parent 5813f8fab8
commit 65a67f1bac
6 changed files with 92 additions and 89 deletions

View File

@@ -14,6 +14,8 @@
WritePixels: https://github.com/TLINDEN/testgol/tree/wrpixels WritePixels: https://github.com/TLINDEN/testgol/tree/wrpixels
https://www.tasnimzotder.com/blog/optimizing-game-of-life-algorithm https://www.tasnimzotder.com/blog/optimizing-game-of-life-algorithm
- show gridlines menu has no effect of grid was enabled with -g
- Speed - Speed
https://conwaylife.com/forums/viewtopic.php?f=7&t=3237 https://conwaylife.com/forums/viewtopic.php?f=7&t=3237

View File

View File

@@ -15,26 +15,26 @@ import (
// all the settings comming from commandline, but maybe tweaked later from the UI // all the settings comming from commandline, but maybe tweaked later from the UI
type Config struct { type Config struct {
Width, Height, Cellsize, Density int // measurements Width, Height, Cellsize, Density int // measurements
ScreenWidth, ScreenHeight int ScreenWidth, ScreenHeight int
TPG int // ticks per generation/game speed, 1==max TPG int // ticks per generation/game speed, 1==max
Debug, Empty, Invert, Paused, Markmode, Drawmode bool // game modi Debug, Empty, Paused, Markmode, Drawmode bool // game modi
ShowEvolution, ShowGrid, RunOneStep bool // flags ShowEvolution, ShowGrid, RunOneStep bool // flags
Rule *Rule // which rule to use, default: B3/S23 Rule *Rule // which rule to use, default: B3/S23
RLE *rle.RLE // loaded GOL pattern from RLE file RLE *rle.RLE // loaded GOL pattern from RLE file
Statefile string // load game state from it if non-nil Statefile string // load game state from it if non-nil
StateGrid *Grid // a grid from a statefile StateGrid *Grid // a grid from a statefile
Wrap bool // wether wraparound mode is in place or not Wrap bool // wether wraparound mode is in place or not
ShowVersion bool ShowVersion bool
UseShader bool // to use a shader to render alife cells UseShader bool // to use a shader to render alife cells
Restart, RestartGrid, RestartCache bool Restart, RestartGrid, RestartCache bool
StartWithMenu bool StartWithMenu bool
Zoomfactor int Zoomfactor int
ZoomOutFactor int ZoomOutFactor int
InitialCamPos []float64 InitialCamPos []float64
DelayedStart bool // if true game, we wait. like pause but program induced DelayedStart bool // if true game, we wait. like pause but program induced
Theme string Theme string
ThemeManager ThemeManager ThemeManager ThemeManager
// for internal profiling // for internal profiling
ProfileFile string ProfileFile string
@@ -52,7 +52,7 @@ const (
DEFAULT_CELLSIZE = 4 DEFAULT_CELLSIZE = 4
DEFAULT_ZOOMFACTOR = 150 DEFAULT_ZOOMFACTOR = 150
DEFAULT_GEOM = "640x384" DEFAULT_GEOM = "640x384"
DEFAULT_THEME = "light" // inverse => "dark" DEFAULT_THEME = "standard" // "light" // inverse => "dark"
) )
const KEYBINDINGS string = ` const KEYBINDINGS string = `
@@ -229,8 +229,7 @@ func ParseCommandline() (*Config, error) {
pflag.BoolVarP(&config.Empty, "empty", "e", false, "start with an empty screen") pflag.BoolVarP(&config.Empty, "empty", "e", false, "start with an empty screen")
// style // style
pflag.BoolVarP(&config.Invert, "invert", "i", false, "invert colors (dead cell: black)") pflag.StringVarP(&config.Theme, "theme", "T", DEFAULT_THEME, "color theme: standard, dark, light (default: standard)")
pflag.StringVarP(&config.Theme, "theme", "T", "light", "color theme: dark, light (default: light)")
pflag.BoolVarP(&config.ShowEvolution, "show-evolution", "s", false, "show evolution traces") pflag.BoolVarP(&config.ShowEvolution, "show-evolution", "s", false, "show evolution traces")
pflag.BoolVarP(&config.Wrap, "wrap-around", "w", false, "wrap around grid mode") pflag.BoolVarP(&config.Wrap, "wrap-around", "w", false, "wrap around grid mode")
@@ -260,10 +259,6 @@ func ParseCommandline() (*Config, error) {
config.SetupCamera() config.SetupCamera()
if config.Theme == "light" && config.Invert {
config.Theme = "dark"
}
config.ThemeManager = NewThemeManager(config.Theme, config.Cellsize) config.ThemeManager = NewThemeManager(config.Theme, config.Cellsize)
//repr.Println(config) //repr.Println(config)
@@ -278,21 +273,6 @@ func (config *Config) ToggleDebugging() {
config.Debug = !config.Debug config.Debug = !config.Debug
} }
func (config *Config) ToggleInvert() {
config.Invert = !config.Invert
switch config.ThemeManager.GetCurrentThemeName() {
case "dark":
config.ThemeManager.SetCurrentTheme("light")
case "light":
config.ThemeManager.SetCurrentTheme("dark")
default:
fmt.Println("unable to invert custom theme, only possible with dark and light themes.")
}
config.RestartCache = true
}
func (config *Config) SwitchTheme(theme string) { func (config *Config) SwitchTheme(theme string) {
config.ThemeManager.SetCurrentTheme(theme) config.ThemeManager.SetCurrentTheme(theme)
} }

View File

@@ -93,12 +93,6 @@ func (scene *SceneOptions) Init() {
}) })
scene.SetInitialValue(debugging, scene.Config.Debug) scene.SetInitialValue(debugging, scene.Config.Debug)
invert := NewCheckbox("Invert",
func(args *widget.CheckboxChangedEventArgs) {
scene.Config.ToggleInvert()
})
scene.SetInitialValue(invert, scene.Config.Invert)
gridlines := NewCheckbox("Show grid lines", gridlines := NewCheckbox("Show grid lines",
func(args *widget.CheckboxChangedEventArgs) { func(args *widget.CheckboxChangedEventArgs) {
scene.Config.ToggleGridlines() scene.Config.ToggleGridlines()
@@ -138,7 +132,6 @@ func (scene *SceneOptions) Init() {
rowContainer.AddChild(pause) rowContainer.AddChild(pause)
rowContainer.AddChild(debugging) rowContainer.AddChild(debugging)
rowContainer.AddChild(invert)
rowContainer.AddChild(gridlines) rowContainer.AddChild(gridlines)
rowContainer.AddChild(evolution) rowContainer.AddChild(evolution)
rowContainer.AddChild(wrap) rowContainer.AddChild(wrap)

View File

@@ -3,7 +3,6 @@ package main
import ( import (
"fmt" "fmt"
"image" "image"
"image/color"
"log" "log"
"unsafe" "unsafe"
@@ -706,15 +705,3 @@ func (scene *ScenePlay) CountNeighbors(x, y int) int {
return sum return sum
} }
// fill a cell with the given color
func FillCell(tile *ebiten.Image, cellsize int, col color.RGBA) {
vector.DrawFilledRect(
tile,
float32(1),
float32(1),
float32(cellsize),
float32(cellsize),
col, false,
)
}

View File

@@ -1,9 +1,12 @@
package main package main
import ( import (
"fmt"
"image/color" "image/color"
"log"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
) )
// Color definitions. ColLife could be black or white depending on theme // Color definitions. ColLife could be black or white depending on theme
@@ -28,18 +31,19 @@ type Theme struct {
} }
// create a new theme // create a new theme
func NewTheme(life, dead, old, age1, age2, age3, age4, grid color.RGBA, cellsize int, name string) Theme { func NewTheme(life, dead, old, age1, age2, age3, age4, grid string,
cellsize int, name string) Theme {
theme := Theme{ theme := Theme{
Name: name, Name: name,
Colors: map[int]color.RGBA{ Colors: map[int]color.RGBA{
ColLife: life, ColLife: HexColor2RGBA(life),
ColDead: dead, ColDead: HexColor2RGBA(dead),
ColGrid: grid, ColGrid: HexColor2RGBA(grid),
ColAge1: age1, ColAge1: HexColor2RGBA(age1),
ColAge2: age2, ColAge2: HexColor2RGBA(age2),
ColAge3: age3, ColAge3: HexColor2RGBA(age3),
ColAge4: age4, ColAge4: HexColor2RGBA(age4),
ColOld: old, ColOld: HexColor2RGBA(old),
}, },
} }
@@ -72,35 +76,49 @@ type ThemeManager struct {
// Manager is used to easily switch themes from cli or menu // Manager is used to easily switch themes from cli or menu
func NewThemeManager(initial string, cellsize int) ThemeManager { func NewThemeManager(initial string, cellsize int) ThemeManager {
light := NewTheme( light := NewTheme(
color.RGBA{0, 0, 0, 0xff}, // life "000000", // life
color.RGBA{200, 200, 200, 0xff}, // dead "c8c8c8", // dead
color.RGBA{255, 30, 30, 0xff}, // old "ff1e1e", // old
color.RGBA{255, 195, 97, 0xff}, // age 1..4 "ffc361", // age 1..4
color.RGBA{255, 211, 140, 0xff}, "ffd38c",
color.RGBA{255, 227, 181, 0xff}, "ffe3b5",
color.RGBA{255, 240, 224, 0xff}, "fff0e0",
color.RGBA{128, 128, 128, 0xff}, // grid "808080", // grid
cellsize, cellsize,
"light", "light",
) )
dark := NewTheme( dark := NewTheme(
color.RGBA{200, 200, 200, 0xff}, // life "c8c8c8", // life
color.RGBA{0, 0, 0, 0xff}, // dead "000000", // dead
color.RGBA{255, 30, 30, 0xff}, // old "ff1e1e", // old
color.RGBA{82, 38, 0, 0xff}, // age 1..4 "522600", // age 1..4
color.RGBA{66, 35, 0, 0xff}, "422300",
color.RGBA{43, 27, 0, 0xff}, "2b1b00",
color.RGBA{25, 17, 0, 0xff}, "191100",
color.RGBA{128, 128, 128, 0xff}, // grid "808080", // grid
cellsize,
"dark",
)
standard := NewTheme(
"e15f0b", // life
"5a5a5a", // dead
"e13c0b", // old
"7b5e4b", // age 1..4
"735f52",
"6c6059",
"635d59",
"808080", // grid
cellsize, cellsize,
"dark", "dark",
) )
manager := ThemeManager{ manager := ThemeManager{
Themes: map[string]Theme{ Themes: map[string]Theme{
"dark": dark, "dark": dark,
"light": light, "light": light,
"standard": standard,
}, },
Theme: initial, Theme: initial,
} }
@@ -121,3 +139,26 @@ func (manager *ThemeManager) SetCurrentTheme(theme string) {
manager.Theme = theme manager.Theme = theme
} }
} }
// fill a cell with the given color
func FillCell(tile *ebiten.Image, cellsize int, col color.RGBA) {
vector.DrawFilledRect(
tile,
float32(1),
float32(1),
float32(cellsize),
float32(cellsize),
col, false,
)
}
func HexColor2RGBA(hex string) color.RGBA {
var r, g, b uint8
_, err := fmt.Sscanf(hex, "%02x%02x%02x", &r, &g, &b)
if err != nil {
log.Fatalf("failed to parse hex color: %s", err)
}
return color.RGBA{r, g, b, 255}
}