add jpeg generation, refactor

This commit is contained in:
2025-03-27 22:09:43 +03:00
committed by Dmitry Fedotov
parent 878e3d7c05
commit fe94e38589
6 changed files with 223 additions and 103 deletions

47
color.go Normal file
View 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}
}
}