-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
170 lines (131 loc) · 3.9 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package main
import (
"flag"
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
)
var (
Fullscreen = flag.Bool("fullscreen", false, "Starts in fullscreen mode")
Height int
Width int
MatrixFont rl.Font
BgColor = rl.Color{R: 10, G: 10, B: 0, A: 100}
HeadGlyphColor = rl.Color{R: 185, G: 255, B: 185, A: 255}
MaxTailSize = 50
GlyphSize = 15
FrameRate = int32(60)
streams []*MatrixStream
BlurSize = float32(8.0)
ShowDebug = false
)
func main() {
flag.Parse()
rl.InitWindow(1280, 768, "Matrix Code")
rl.SetTargetFPS(FrameRate)
MatrixFont = rl.LoadFont("matrix-code-nfi.ttf")
if *Fullscreen {
Width = rl.GetMonitorWidth(0)
Height = rl.GetMonitorHeight(0)
rl.ToggleFullscreen()
} else {
Width = 800
Height = 800
}
rl.SetWindowSize(Width, Height)
rl.SetWindowPosition(10, 30)
// Create a RenderTexture2D to be used for render to texture
target := rl.LoadRenderTexture(int32(Width), int32(Height))
shader := rl.LoadShader("", "shaders/blur.fs")
// Create initial matrix streams
streams = []*MatrixStream{}
for i := 0; i < 100; i++ {
s := NewMatrixStream()
streams = append(streams, s)
}
shaderWindowSizeLoc := rl.GetShaderLocation(shader, "windowSize")
rl.SetShaderValue(shader, shaderWindowSizeLoc, []float32{float32(Width), float32(Height)}, 1)
shaderBlurSizeLoc := rl.GetShaderLocation(shader, "blurSize")
for !rl.WindowShouldClose() {
handleUserInput()
rl.BeginDrawing()
rl.BeginTextureMode(target)
rl.ClearBackground(rl.Black)
// rl.ClearBackground(rl.Blank)
// // Draw the streams
for _, s := range streams {
s.Draw()
}
rl.EndTextureMode()
rl.SetShaderValue(shader, shaderBlurSizeLoc, []float32{BlurSize}, 0)
rl.BeginShaderMode(shader)
rl.DrawTextureRec(target.Texture, rl.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), rl.NewVector2(0, 0), rl.White)
rl.EndShaderMode()
rl.DrawTextureRec(target.Texture, rl.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), rl.NewVector2(0, 0), rl.Color{255, 255, 255, 128})
// Help GUI
if ShowDebug {
rl.DrawText(fmt.Sprintf("%f FPS", rl.GetFPS()), 10, 10, 10, rl.White)
rl.DrawText(fmt.Sprintf("A/Z - Change glyph lifetime = %d", MaxTailSize), 10, 30, 10, rl.White)
rl.DrawText(fmt.Sprintf("S/X - Change glyph size = %d", GlyphSize), 10, 50, 10, rl.White)
rl.DrawText(fmt.Sprintf("D/C - Change framerate = %d", FrameRate), 10, 70, 10, rl.White)
rl.DrawText(fmt.Sprintf("F/V - Change qt of streams = %d", len(streams)), 10, 90, 10, rl.White)
rl.DrawText(fmt.Sprintf("G/B - Change blur size = %f", BlurSize), 10, 110, 10, rl.White)
} else if rl.GetTime() < 8 {
rl.DrawText("Press F1 to show commands", 10, 10, 18, rl.White)
}
rl.EndDrawing()
}
rl.UnloadFont(MatrixFont)
rl.UnloadShader(shader)
rl.UnloadRenderTexture(target)
rl.ClearDroppedFiles()
rl.CloseWindow()
}
func handleUserInput() {
if rl.IsKeyPressed(rl.KeyF1) {
ShowDebug = !ShowDebug
}
// A/Z - Change tail size
// TODO: It's not working as expected, leaving some glyphs showing forever...
if rl.IsKeyDown(rl.KeyA) {
MaxTailSize++
} else if rl.IsKeyDown(rl.KeyZ) {
if MaxTailSize > 2 {
MaxTailSize--
}
}
// S/X - Change glyph size
if rl.IsKeyDown(rl.KeyS) {
GlyphSize++
} else if rl.IsKeyDown(rl.KeyX) {
if GlyphSize > 2 {
GlyphSize--
}
}
// D/C - Change framerate
if rl.IsKeyDown(rl.KeyD) {
FrameRate++
rl.SetTargetFPS(FrameRate)
} else if rl.IsKeyDown(rl.KeyC) {
if FrameRate > 2 {
FrameRate--
rl.SetTargetFPS(FrameRate)
}
}
// F/V - Change number of matrix streams
if rl.IsKeyDown(rl.KeyF) {
s := NewMatrixStream()
streams = append(streams, s)
} else if rl.IsKeyDown(rl.KeyV) {
if len(streams) > 1 {
streams = streams[:len(streams)-1]
}
}
// G/B - Change blur size
if rl.IsKeyDown(rl.KeyG) {
BlurSize += 0.5
} else if rl.IsKeyDown(rl.KeyB) {
if BlurSize > 0 {
BlurSize -= 0.5
}
}
}