add gradient and random effect.
This commit is contained in:
@@ -188,11 +188,17 @@ func (col *Color) Interpolate(other Color, fac float64) Color {
|
||||
return Color{K: &k3}
|
||||
}
|
||||
|
||||
if fac < 0.000001 {
|
||||
return *col
|
||||
} else if fac > 0.999999 {
|
||||
return other
|
||||
}
|
||||
|
||||
// Get the colorful values.
|
||||
cvCF := col.colorful()
|
||||
otherCF := other.colorful()
|
||||
|
||||
// Blend and normalize
|
||||
// Blend and normalize (clamping is hax to avoid issues with some colors)
|
||||
blended := cvCF.BlendLuv(otherCF, fac)
|
||||
blendedHue, blendedSat, _ := blended.Hsv()
|
||||
blendedHs := HueSat{Hue: blendedHue, Sat: blendedSat}
|
||||
@@ -253,7 +259,7 @@ func (col *Color) colorful() colorful.Color {
|
||||
case col.XY != nil:
|
||||
return colorful.Xyy(col.XY.X, col.XY.Y, 0.5)
|
||||
default:
|
||||
return colorful.Color{R: 255, B: 255, G: 255}
|
||||
return colorful.Color{R: 1, B: 1, G: 1}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package color
|
||||
|
||||
import "github.com/lucasb-eyer/go-colorful"
|
||||
import (
|
||||
"github.com/lucasb-eyer/go-colorful"
|
||||
"math"
|
||||
)
|
||||
|
||||
type HueSat struct {
|
||||
Hue float64 `json:"hue"`
|
||||
@@ -13,5 +16,5 @@ func (hs HueSat) ToXY() XY {
|
||||
|
||||
func (hs HueSat) ToRGB() RGB {
|
||||
c := colorful.Hsv(hs.Hue, hs.Sat, 1)
|
||||
return RGB{Red: c.R, Green: c.G, Blue: c.B}
|
||||
return RGB{Red: math.Max(c.R, 0), Green: math.Max(c.G, 0), Blue: math.Max(c.B, 0)}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,14 @@ func (rgb RGB) AtIntensity(intensity float64) RGB {
|
||||
return RGB{Red: hsv2.R, Green: hsv2.G, Blue: hsv2.B}
|
||||
}
|
||||
|
||||
func (rgb RGB) Bytes() [3]uint8 {
|
||||
return [3]uint8{
|
||||
uint8(rgb.Red * 255.0),
|
||||
uint8(rgb.Green * 255.0),
|
||||
uint8(rgb.Blue * 255.0),
|
||||
}
|
||||
}
|
||||
|
||||
func (rgb RGB) ToHS() HueSat {
|
||||
hue, sat, _ := colorful.Color{R: rgb.Red, G: rgb.Green, B: rgb.Blue}.Hsv()
|
||||
return HueSat{Hue: hue, Sat: sat}
|
||||
|
||||
@@ -3,3 +3,8 @@ package gentools
|
||||
func Ptr[T any](t T) *T {
|
||||
return &t
|
||||
}
|
||||
|
||||
func ShallowCopy[T any](t *T) *T {
|
||||
tCopy := *t
|
||||
return &tCopy
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user