mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-16 12:10:58 +01:00
removed invert option, added new standard theme (orange on grey)
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -14,6 +14,8 @@
|
||||
WritePixels: https://github.com/TLINDEN/testgol/tree/wrpixels
|
||||
https://www.tasnimzotder.com/blog/optimizing-game-of-life-algorithm
|
||||
|
||||
- show gridlines menu has no effect of grid was enabled with -g
|
||||
|
||||
- Speed
|
||||
https://conwaylife.com/forums/viewtopic.php?f=7&t=3237
|
||||
|
||||
|
||||
@@ -15,26 +15,26 @@ import (
|
||||
|
||||
// all the settings comming from commandline, but maybe tweaked later from the UI
|
||||
type Config struct {
|
||||
Width, Height, Cellsize, Density int // measurements
|
||||
ScreenWidth, ScreenHeight int
|
||||
TPG int // ticks per generation/game speed, 1==max
|
||||
Debug, Empty, Invert, Paused, Markmode, Drawmode bool // game modi
|
||||
ShowEvolution, ShowGrid, RunOneStep bool // flags
|
||||
Rule *Rule // which rule to use, default: B3/S23
|
||||
RLE *rle.RLE // loaded GOL pattern from RLE file
|
||||
Statefile string // load game state from it if non-nil
|
||||
StateGrid *Grid // a grid from a statefile
|
||||
Wrap bool // wether wraparound mode is in place or not
|
||||
ShowVersion bool
|
||||
UseShader bool // to use a shader to render alife cells
|
||||
Restart, RestartGrid, RestartCache bool
|
||||
StartWithMenu bool
|
||||
Zoomfactor int
|
||||
ZoomOutFactor int
|
||||
InitialCamPos []float64
|
||||
DelayedStart bool // if true game, we wait. like pause but program induced
|
||||
Theme string
|
||||
ThemeManager ThemeManager
|
||||
Width, Height, Cellsize, Density int // measurements
|
||||
ScreenWidth, ScreenHeight int
|
||||
TPG int // ticks per generation/game speed, 1==max
|
||||
Debug, Empty, Paused, Markmode, Drawmode bool // game modi
|
||||
ShowEvolution, ShowGrid, RunOneStep bool // flags
|
||||
Rule *Rule // which rule to use, default: B3/S23
|
||||
RLE *rle.RLE // loaded GOL pattern from RLE file
|
||||
Statefile string // load game state from it if non-nil
|
||||
StateGrid *Grid // a grid from a statefile
|
||||
Wrap bool // wether wraparound mode is in place or not
|
||||
ShowVersion bool
|
||||
UseShader bool // to use a shader to render alife cells
|
||||
Restart, RestartGrid, RestartCache bool
|
||||
StartWithMenu bool
|
||||
Zoomfactor int
|
||||
ZoomOutFactor int
|
||||
InitialCamPos []float64
|
||||
DelayedStart bool // if true game, we wait. like pause but program induced
|
||||
Theme string
|
||||
ThemeManager ThemeManager
|
||||
|
||||
// for internal profiling
|
||||
ProfileFile string
|
||||
@@ -52,7 +52,7 @@ const (
|
||||
DEFAULT_CELLSIZE = 4
|
||||
DEFAULT_ZOOMFACTOR = 150
|
||||
DEFAULT_GEOM = "640x384"
|
||||
DEFAULT_THEME = "light" // inverse => "dark"
|
||||
DEFAULT_THEME = "standard" // "light" // inverse => "dark"
|
||||
)
|
||||
|
||||
const KEYBINDINGS string = `
|
||||
@@ -229,8 +229,7 @@ func ParseCommandline() (*Config, error) {
|
||||
pflag.BoolVarP(&config.Empty, "empty", "e", false, "start with an empty screen")
|
||||
|
||||
// style
|
||||
pflag.BoolVarP(&config.Invert, "invert", "i", false, "invert colors (dead cell: black)")
|
||||
pflag.StringVarP(&config.Theme, "theme", "T", "light", "color theme: dark, light (default: light)")
|
||||
pflag.StringVarP(&config.Theme, "theme", "T", DEFAULT_THEME, "color theme: standard, dark, light (default: standard)")
|
||||
|
||||
pflag.BoolVarP(&config.ShowEvolution, "show-evolution", "s", false, "show evolution traces")
|
||||
pflag.BoolVarP(&config.Wrap, "wrap-around", "w", false, "wrap around grid mode")
|
||||
@@ -260,10 +259,6 @@ func ParseCommandline() (*Config, error) {
|
||||
|
||||
config.SetupCamera()
|
||||
|
||||
if config.Theme == "light" && config.Invert {
|
||||
config.Theme = "dark"
|
||||
}
|
||||
|
||||
config.ThemeManager = NewThemeManager(config.Theme, config.Cellsize)
|
||||
|
||||
//repr.Println(config)
|
||||
@@ -278,21 +273,6 @@ func (config *Config) ToggleDebugging() {
|
||||
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) {
|
||||
config.ThemeManager.SetCurrentTheme(theme)
|
||||
}
|
||||
|
||||
@@ -93,12 +93,6 @@ func (scene *SceneOptions) Init() {
|
||||
})
|
||||
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",
|
||||
func(args *widget.CheckboxChangedEventArgs) {
|
||||
scene.Config.ToggleGridlines()
|
||||
@@ -138,7 +132,6 @@ func (scene *SceneOptions) Init() {
|
||||
|
||||
rowContainer.AddChild(pause)
|
||||
rowContainer.AddChild(debugging)
|
||||
rowContainer.AddChild(invert)
|
||||
rowContainer.AddChild(gridlines)
|
||||
rowContainer.AddChild(evolution)
|
||||
rowContainer.AddChild(wrap)
|
||||
|
||||
13
src/play.go
13
src/play.go
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"log"
|
||||
"unsafe"
|
||||
|
||||
@@ -706,15 +705,3 @@ func (scene *ScenePlay) CountNeighbors(x, y int) int {
|
||||
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
||||
95
src/theme.go
95
src/theme.go
@@ -1,9 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||
)
|
||||
|
||||
// Color definitions. ColLife could be black or white depending on theme
|
||||
@@ -28,18 +31,19 @@ type Theme struct {
|
||||
}
|
||||
|
||||
// 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{
|
||||
Name: name,
|
||||
Colors: map[int]color.RGBA{
|
||||
ColLife: life,
|
||||
ColDead: dead,
|
||||
ColGrid: grid,
|
||||
ColAge1: age1,
|
||||
ColAge2: age2,
|
||||
ColAge3: age3,
|
||||
ColAge4: age4,
|
||||
ColOld: old,
|
||||
ColLife: HexColor2RGBA(life),
|
||||
ColDead: HexColor2RGBA(dead),
|
||||
ColGrid: HexColor2RGBA(grid),
|
||||
ColAge1: HexColor2RGBA(age1),
|
||||
ColAge2: HexColor2RGBA(age2),
|
||||
ColAge3: HexColor2RGBA(age3),
|
||||
ColAge4: HexColor2RGBA(age4),
|
||||
ColOld: HexColor2RGBA(old),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -72,35 +76,49 @@ type ThemeManager struct {
|
||||
// Manager is used to easily switch themes from cli or menu
|
||||
func NewThemeManager(initial string, cellsize int) ThemeManager {
|
||||
light := NewTheme(
|
||||
color.RGBA{0, 0, 0, 0xff}, // life
|
||||
color.RGBA{200, 200, 200, 0xff}, // dead
|
||||
color.RGBA{255, 30, 30, 0xff}, // old
|
||||
color.RGBA{255, 195, 97, 0xff}, // age 1..4
|
||||
color.RGBA{255, 211, 140, 0xff},
|
||||
color.RGBA{255, 227, 181, 0xff},
|
||||
color.RGBA{255, 240, 224, 0xff},
|
||||
color.RGBA{128, 128, 128, 0xff}, // grid
|
||||
"000000", // life
|
||||
"c8c8c8", // dead
|
||||
"ff1e1e", // old
|
||||
"ffc361", // age 1..4
|
||||
"ffd38c",
|
||||
"ffe3b5",
|
||||
"fff0e0",
|
||||
"808080", // grid
|
||||
cellsize,
|
||||
"light",
|
||||
)
|
||||
|
||||
dark := NewTheme(
|
||||
color.RGBA{200, 200, 200, 0xff}, // life
|
||||
color.RGBA{0, 0, 0, 0xff}, // dead
|
||||
color.RGBA{255, 30, 30, 0xff}, // old
|
||||
color.RGBA{82, 38, 0, 0xff}, // age 1..4
|
||||
color.RGBA{66, 35, 0, 0xff},
|
||||
color.RGBA{43, 27, 0, 0xff},
|
||||
color.RGBA{25, 17, 0, 0xff},
|
||||
color.RGBA{128, 128, 128, 0xff}, // grid
|
||||
"c8c8c8", // life
|
||||
"000000", // dead
|
||||
"ff1e1e", // old
|
||||
"522600", // age 1..4
|
||||
"422300",
|
||||
"2b1b00",
|
||||
"191100",
|
||||
"808080", // grid
|
||||
cellsize,
|
||||
"dark",
|
||||
)
|
||||
|
||||
standard := NewTheme(
|
||||
"e15f0b", // life
|
||||
"5a5a5a", // dead
|
||||
"e13c0b", // old
|
||||
"7b5e4b", // age 1..4
|
||||
"735f52",
|
||||
"6c6059",
|
||||
"635d59",
|
||||
"808080", // grid
|
||||
cellsize,
|
||||
"dark",
|
||||
)
|
||||
|
||||
manager := ThemeManager{
|
||||
Themes: map[string]Theme{
|
||||
"dark": dark,
|
||||
"light": light,
|
||||
"dark": dark,
|
||||
"light": light,
|
||||
"standard": standard,
|
||||
},
|
||||
Theme: initial,
|
||||
}
|
||||
@@ -121,3 +139,26 @@ func (manager *ThemeManager) SetCurrentTheme(theme string) {
|
||||
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}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user