WIP
This commit is contained in:
47
color.go
Normal file
47
color.go
Normal file
@@ -0,0 +1,47 @@
|
||||
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}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user