forked from oakmound/oak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.go
84 lines (75 loc) · 1.84 KB
/
core.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
package main
import (
"image/color"
"strconv"
"github.com/200sc/go-dist/floatrange"
"image"
"github.com/oakmound/oak"
"github.com/oakmound/oak/render"
"github.com/oakmound/oak/scene"
)
var (
font *render.Font
r, g, b, a float64
diff = floatrange.NewSpread(0, 10)
limit = floatrange.NewLinear(0, 255)
)
type floatStringer struct {
f *float64
}
func (fs floatStringer) String() string {
return strconv.Itoa(int(*fs.f))
}
func main() {
oak.Add("demo",
// Init
func(prevScene string, payload interface{}) {
fg := render.FontGenerator{
File: "luxisr.ttf",
Color: image.NewUniform(color.RGBA{255, 0, 0, 255}),
Size: 400,
Hinting: "",
DPI: 10,
}
r = 255
font = fg.Generate()
render.Draw(font.NewStrText("Rainbow", 200, 200), 0)
render.Draw(font.NewText(floatStringer{&r}, 200, 250), 0)
render.Draw(font.NewText(floatStringer{&g}, 320, 250), 0)
render.Draw(font.NewText(floatStringer{&b}, 440, 250), 0)
font2 := font.Copy()
font2.Color = image.NewUniform(color.RGBA{255, 255, 255, 255})
font2.Refresh()
// Could give each r,g,b a color which is just the r,g,b value
render.Draw(font2.NewStrText("r", 170, 250), 0)
render.Draw(font2.NewStrText("g", 290, 250), 0)
render.Draw(font2.NewStrText("b", 410, 250), 0)
},
// Loop
func() bool {
r = limit.EnforceRange(r + diff.Poll())
g = limit.EnforceRange(g + diff.Poll())
b = limit.EnforceRange(b + diff.Poll())
// This should be a function in oak to just set color source
// (or texture source)
font.Drawer.Src = image.NewUniform(
color.RGBA{
uint8(r),
uint8(g),
uint8(b),
255,
},
)
return true
},
// End
func() (string, *scene.Result) {
return "demo", nil
},
)
render.SetDrawStack(
render.NewHeap(false),
render.NewDrawFPS(),
)
oak.Init("demo")
}