-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuniform.go
42 lines (33 loc) · 862 Bytes
/
uniform.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
// See LICENSE.txt for licensing information.
// Uniform generates an uniformly colored icon.
// Useful for testing, not very interesting in practice.
package ricons
import (
"image"
"image/color"
"image/draw"
"math/rand"
"time"
)
type uniformIconGen struct {
r *rand.Rand
}
func (g *uniformIconGen) String() string {
return "uniform: single uniform color"
}
func (g *uniformIconGen) Generate(i *Icon) error {
re := uint8(g.r.Intn(255))
gr := uint8(g.r.Intn(255))
bl := uint8(g.r.Intn(255))
bg := image.NewUniform(&color.RGBA{re, gr, bl, 0xff})
draw.Draw(i.Image, i.Dim, bg, image.ZP, draw.Src)
return nil
}
func (g *uniformIconGen) NewIcon(width, height int) (*Icon, error) {
i := NewIcon(width, height)
return i, g.Generate(i)
}
func init() {
g := &uniformIconGen{rand.New(rand.NewSource(time.Now().Unix()))}
Register("uniform", g)
}