Files
barnsley-fern-go/color.go
Dmitry Fedotov c3b2036713 WIP
2025-03-25 23:55:13 +03:00

48 lines
754 B
Go

package main
import (
"image/color"
"math/rand"
"time"
)
type colorFunc func(float64, float64, time.Time) color.Color
func newColorFunc(c colormode) colorFunc {
start := time.Now()
return func(x, y float64, t time.Time) color.Color {
var (
r, g, b, a uint8
)
switch c {
case crandom:
r = uint8(rand.Intn(256))
g = uint8(rand.Intn(256))
b = uint8(rand.Intn(256))
a = 255
case ctimed:
n := time.Since(start).Nanoseconds()
r = uint8(n % 256)
g = uint8((n + 128) % 256)
//b = uint8((n + 1) % 256)
a = 255
case crainbow:
r = uint8(y * 256)
g = uint8(x * 256)
b = uint8(((y - x) - min(x, y)) * 256)
a = 255
default:
r, g, b, a = 0, 153, 0, 255
}
return color.RGBA{r, g, b, a}
}
}