Files
game-of-life/ui/colors.go
Natercio Moniz ea5b5c4e75 Initial commit
implemented the game of life variation with hexagonal grid
2025-12-16 11:33:00 +00:00

26 lines
539 B
Go

package ui
import (
"image/color"
"math"
)
func mixColors(a, b color.Color, percent float64) color.Color {
rgba := func(c color.Color) (r, g, b, a uint8) {
r16, g16, b16, a16 := c.RGBA()
return uint8(r16 >> 8), uint8(g16 >> 8), uint8(b16 >> 8), uint8(a16 >> 8)
}
lerp := func(x, y uint8) uint8 {
return uint8(math.Round(float64(x) + percent*(float64(y)-float64(x))))
}
r1, g1, b1, a1 := rgba(a)
r2, g2, b2, a2 := rgba(b)
return color.RGBA{
R: lerp(r1, r2),
G: lerp(g1, g2),
B: lerp(b1, b2),
A: lerp(a1, a2),
}
}