-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathglyphs.go
55 lines (41 loc) · 980 Bytes
/
glyphs.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
package script
import (
"math/rand"
"github.com/fogleman/gg"
)
// Glyph represents a single glyph
type Glyph struct {
Representation string
Strokes []Stroke
Width int
Height int
GridSizeX int
GridSizeY int
}
func generateGlyph(representation string, width int, height int) Glyph {
var newStroke Stroke
numberOfStrokes := rand.Intn(3) + 1
strokes := []Stroke{}
glyph := Glyph{
Representation: representation,
Width: width,
Height: height,
GridSizeX: 5,
GridSizeY: 5,
}
for i := 0; i < numberOfStrokes; i++ {
newStroke = glyph.randomStroke()
strokes = append(strokes, newStroke)
}
glyph.Strokes = strokes
return glyph
}
// Render draws and saves a glyph
func (glyph Glyph) Render() {
image := gg.NewContext(glyph.Width, glyph.Height)
for _, s := range glyph.Strokes {
s.Render(*image)
}
fileName := "./output/" + glyph.Representation + ".png"
image.SavePNG(fileName)
}