Files
sumi/internal/graphics/graphics.go
2025-12-26 00:55:59 -06:00

63 lines
1.2 KiB
Go

package graphics
import (
"math/rand"
rl "github.com/gen2brain/raylib-go/raylib"
)
var (
FlourescentHues = []float32{
0, // hot magenta-red
30, // neon orange
60, // acid yellow
120, // laser green
180, // cyan
210, // electric blue
270, // ultraviolet purple
}
FlourescentColors = makeFlourescentColors()
)
func makeFlourescentColors() []rl.Color {
fc := make([]rl.Color, len(FlourescentHues))
for i, hue := range(FlourescentHues) {
fc[i] = rl.ColorFromHSV(hue, 1.0, 1.0)
}
return fc
}
type ColorCycle interface {
Next() rl.Color
}
type ArrayBackedColorCycle struct {
colors []rl.Color
index int
}
func NewFixedColorCycle(colors []rl.Color) ArrayBackedColorCycle {
return ArrayBackedColorCycle {
colors: colors,
index: 0,
}
}
func (c ArrayBackedColorCycle) Shuffle(seed int64) ColorCycle {
r := rand.New(rand.NewSource(seed))
cprime := &ArrayBackedColorCycle {
colors: make([]rl.Color, len(c.colors)),
index: 0,
}
r.Shuffle(len(c.colors), func(i, j int) {
cprime.colors[i] = c.colors[j]
})
return cprime
}
func (c *ArrayBackedColorCycle) Next() rl.Color {
color := c.colors[c.index]
c.index = (c.index + 1) % len(c.colors)
return color
}