-
Notifications
You must be signed in to change notification settings - Fork 84
/
colorGenerator.go
114 lines (94 loc) · 2.55 KB
/
colorGenerator.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
114
package particle
import (
"image/color"
"math"
"github.com/oakmound/oak/shape"
"github.com/200sc/go-dist/intrange"
)
// A ColorGenerator generates ColorParticles
type ColorGenerator struct {
BaseGenerator
StartColor, StartColorRand color.Color
EndColor, EndColorRand color.Color
// The size, in pixel radius, of spawned particles
Size intrange.Range
//
// Some sort of particle type, for rendering triangles or squares or circles...
Shape shape.Shape
}
// NewColorGenerator returns a new color generator
func NewColorGenerator(options ...func(Generator)) Generator {
g := new(ColorGenerator)
g.setDefaults()
for _, opt := range options {
opt(g)
}
return g
}
func (cg *ColorGenerator) setDefaults() {
cg.BaseGenerator.setDefaults()
cg.StartColor = color.RGBA{0, 0, 0, 0}
cg.StartColorRand = color.RGBA{0, 0, 0, 0}
cg.EndColor = color.RGBA{0, 0, 0, 0}
cg.EndColorRand = color.RGBA{0, 0, 0, 0}
cg.Size = intrange.Constant(1)
cg.Shape = shape.Square
}
// Generate creates a source using this generator
func (cg *ColorGenerator) Generate(layer int) *Source {
// Convert rotation from degrees to radians
if cg.Rotation != nil {
cg.Rotation = cg.Rotation.Mult(math.Pi / 180)
}
return NewSource(cg, layer)
}
// GenerateParticle creates a particle from a generator
func (cg *ColorGenerator) GenerateParticle(bp *baseParticle) Particle {
return &ColorParticle{
baseParticle: bp,
startColor: randColor(cg.StartColor, cg.StartColorRand),
endColor: randColor(cg.EndColor, cg.EndColorRand),
size: cg.Size.Poll(),
}
}
// GetParticleSize on a color generator returns that the particles
// are per-particle specificially sized
func (cg *ColorGenerator) GetParticleSize() (float64, float64, bool) {
return 0, 0, true
}
// Coloration
//
// SetStartColor lets cg have its color be set
func (cg *ColorGenerator) SetStartColor(sc, scr color.Color) {
cg.StartColor = sc
cg.StartColorRand = scr
}
// SetEndColor lets cg have its end color be set
func (cg *ColorGenerator) SetEndColor(ec, ecr color.Color) {
cg.EndColor = ec
cg.EndColorRand = ecr
}
//
// Sizing
//
// A Sizeable is a generator that can have some size set to it
type Sizeable interface {
SetSize(i intrange.Range)
}
// Size is an option to set a Sizeable size
func Size(i intrange.Range) func(Generator) {
return func(g Generator) {
g.(Sizeable).SetSize(i)
}
}
// SetSize satisfies Sizeable
func (cg *ColorGenerator) SetSize(i intrange.Range) {
cg.Size = i
}
//
// Shaping
//
// SetShape satisfies Shapeable
func (cg *ColorGenerator) SetShape(sf shape.Shape) {
cg.Shape = sf
}