-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (60 loc) · 1.4 KB
/
main.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
package main
import (
"image/jpeg"
"log"
"math"
"os"
"github.com/KaviiSuri/wang-tiles/color"
"github.com/KaviiSuri/wang-tiles/linalg"
"github.com/KaviiSuri/wang-tiles/wang"
)
const (
tileHeight = 64
tileWidth = 64
widthInTiles = 13
heightInTiles = 10
tileSetHeight = tileHeight * widthInTiles
tileSetWidth = tileWidth * heightInTiles
)
func stripes(uv linalg.Vec) color.Normalized {
n := 20.0
return color.Normalized{
R: (math.Sin(uv.U()*n) + 1.0) / 2,
G: (math.Sin((uv.U()+uv.V())*n) + 1.0) / 2,
B: (math.Cos(uv.V()*n) + 1.0) / 2,
A: 0.0,
}
}
func circle(uv linalg.Vec) color.Normalized {
center := linalg.NewVec(0.5, 0.5)
radius := .25
if linalg.Sub(center, uv).Len() <= radius {
return color.Normalized{R: 1.0}
}
return color.Normalized{R: 1.0, G: 1.0, B: 1.0}
}
func main() {
filename := "./temp/grid.jpeg"
atlasFile := "./temp/atlas.jpeg"
f, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
defer f.Close()
tileSet := wang.NewWangTileSet(tileWidth, tileHeight)
img := wang.NewWangGrid(tileSet, widthInTiles, heightInTiles, tileWidth, tileHeight)
jpeg.Encode(f, img, nil)
bltrs := [][]uint8{
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 10, 11},
{12, 13, 14, 15},
}
img = wang.NewGridFromBLTRS(bltrs, tileSet, 4, 4, tileWidth, tileHeight)
af, err := os.Create(atlasFile)
defer af.Close()
if err != nil {
log.Fatal(err)
}
jpeg.Encode(af, img, nil)
}