-
Notifications
You must be signed in to change notification settings - Fork 0
/
blend.go
113 lines (107 loc) · 2.25 KB
/
blend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package zedit
import (
"image/color"
"github.com/lucasb-eyer/go-colorful"
"github.com/phrozen/blend"
)
type BlendMode int
const (
BlendColor BlendMode = iota + 1
BlendColorBurn
BlendColorDodge
BlendDarken
BlendDarkerColor
BlendDifference
BlendDivide
BlendExclusion
BlendHardLight
BlendHardMix
BlendHue
BlendLighten
BlendLighterColor
BlendLinearBurn
BlendLinearDodge
BlendLinearLight
BlendLuminosity
BlendMultiply
BlendOverlay
BlendPhoenix
BlendPinLight
BlendReflex
BlendSaturation
BlendScreen
BlendSoftLight
BlendSubstract
BlendVividLight
)
func BlendColors(blending BlendMode, switched bool, c1, c2 color.Color) color.Color {
if switched {
tmp := c2
c2 = c1
c1 = tmp
}
var c color.Color
switch blending {
case BlendColorBurn:
c = blend.ColorBurn(c2, c1)
case BlendColorDodge:
c = blend.ColorDodge(c2, c1)
case BlendDarken:
c = blend.Darken(c2, c1)
case BlendDarkerColor:
c = blend.DarkerColor(c2, c1)
case BlendDifference:
c = blend.Difference(c2, c1)
case BlendDivide:
c = blend.Divide(c2, c1)
case BlendExclusion:
c = blend.Exclusion(c2, c1)
case BlendHardLight:
c = blend.HardLight(c2, c1)
case BlendHardMix:
c = blend.HardMix(c2, c1)
case BlendHue:
c = blend.Hue(c2, c1)
case BlendLighten:
c = blend.Lighten(c2, c1)
case BlendLighterColor:
c = blend.LighterColor(c2, c1)
case BlendLinearBurn:
c = blend.LinearBurn(c2, c1)
case BlendLinearDodge:
c = blend.LinearDodge(c2, c1)
case BlendLinearLight:
c = blend.LinearLight(c2, c1)
case BlendLuminosity:
c = blend.Luminosity(c2, c1)
case BlendMultiply:
c = blend.Multiply(c2, c1)
case BlendOverlay:
c = blend.Overlay(c2, c1)
case BlendPhoenix:
c = blend.Phoenix(c2, c1)
case BlendPinLight:
c = blend.PinLight(c2, c1)
case BlendReflex:
c = blend.Reflex(c2, c1)
case BlendSaturation:
c = blend.Saturation(c2, c1)
case BlendScreen:
c = blend.Screen(c2, c1)
case BlendSoftLight:
c = blend.SoftLight(c2, c1)
case BlendSubstract:
c = blend.Substract(c2, c1)
case BlendVividLight:
c = blend.VividLight(c2, c1)
default:
c = blend.Color(c2, c1)
}
return c
}
func GradientColor(c1, c2 color.Color, t float64) color.Color {
c3, _ := colorful.MakeColor(c1)
c4, _ := colorful.MakeColor(c2)
col := c3.BlendHcl(c4, t)
return col
}