-
Notifications
You must be signed in to change notification settings - Fork 1
/
tunnel.go
80 lines (61 loc) · 1.6 KB
/
tunnel.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
package main
import (
"github.com/rostislavjadavan/gofb"
"math"
"strconv"
)
const (
W = 600
H = 450
)
func main() {
w := gofb.NewWindow("go-fb", 1200, 900, false)
text, err := gofb.NewFont("../assets/uni0553-webfont.ttf", 40)
if err != nil {
panic(err)
}
texture, err := gofb.NewSurfaceFromFile("../assets/pattern.jpg")
if err != nil {
panic(err)
}
surface := gofb.NewSurface(W, H)
surface.Scale = 2
distances := [W][H]int{}
angles := [W][H]int{}
fw := float64(W)
fh := float64(H)
fth := float64(texture.Height)
ftw := float64(texture.Width)
for y := 0; y < H; y++ {
fy := float64(y)
for x := 0; x < W; x++ {
fx := float64(x)
distances[x][y] = int(50.0*fth/math.Sqrt((fx-fw/2.0)*(fx-fw/2.0)+(fy-fh/2.0)*(fy-fh/2.0))) % texture.Height
angles[x][y] = int(0.5 * ftw * math.Atan2(fy-fh/2.0, fx-fw/2.0) / math.Pi)
}
}
var animation float64 = 0
var movement float64 = 0
for w.IsRunning() {
w.StartFrame()
w.Clear(gofb.NewColor3(0, 0, 0))
shiftX := (int)(ftw + animation)
shiftY := (int)(fth + movement)
for y := 0; y < H; y++ {
for x := 0; x < W; x++ {
tX := (distances[x][y] + shiftX) % texture.Width
tY := (angles[x][y] + shiftY) % texture.Height
surface.SetPixel(x, y, texture.GetPixel(tX, tY))
}
}
surface.Draw(0, 0)
animation += float64(w.GetDeltaTimeMs() / 10)
movement += float64(w.GetDeltaTimeMs() / 50)
fps := strconv.Itoa(int(w.GetFPS()))
text.Draw("GOFB TUNNEL: Running "+fps+" frames per second", 100, 800, gofb.NewColor3(0, 0, 0))
w.FinalizeFrame()
}
defer surface.Release()
defer texture.Release()
defer w.Destroy()
}