-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.odin
109 lines (87 loc) · 2.87 KB
/
main.odin
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
package main
import "core:fmt"
import "core:math/rand"
import "core:time"
import rl "vendor:raylib"
Streamer :: struct {
column: i32,
position: f32,
speed: f32,
text: []rune,
}
SCREEN_WIDTH :: 1280
SCREEN_HEIGHT :: 800
CHAR_SIZE :: 12
MAX_STREAMERS :: 200
random_character :: proc() -> rune {
// Use Unicode range similar to original (0x00C0 to 0x1EF)
return rune(rand.int_max(0x1EF - 0x00C0) + 0x00C0)
}
prepare_streamer :: proc(s: ^Streamer) {
if s.text != nil {
delete(s.text)
}
s.column = rand.int31_max(SCREEN_WIDTH / CHAR_SIZE) * CHAR_SIZE
s.position = 0
s.speed = f32(rand.int31_max(40) + 5)
length := rand.int31_max(80) + 10
s.text = make([]rune, length)
for i := 0; i < len(s.text); i += 1 {
s.text[i] = random_character()
}
}
main :: proc() {
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Matrix")
defer rl.CloseWindow()
rl.SetTargetFPS(60)
// Initialize streamers
streamers := make([dynamic]Streamer, MAX_STREAMERS)
defer delete(streamers)
for &s in &streamers {
prepare_streamer(&s)
}
for !rl.WindowShouldClose() {
elapsed := rl.GetFrameTime()
rl.BeginDrawing()
defer rl.EndDrawing()
rl.ClearBackground(rl.BLACK)
for &s in &streamers {
s.position += elapsed * s.speed
for i := 0; i < len(s.text); i += 1 {
y_pos := int(s.position) * CHAR_SIZE - (i * CHAR_SIZE)
if y_pos < -CHAR_SIZE || y_pos > SCREEN_HEIGHT {
continue
}
char_index := (i - int(s.position)) % len(s.text)
if char_index < 0 {
char_index += len(s.text)
}
// Determine character color based on position
color := rl.GREEN
if i == 0 {
color = rl.WHITE
} else if i <= 3 {
color = rl.GRAY
} else if s.speed < 15 {
color = {0, 100, 0, 255} // Dark green
}
// Draw the character
rl.DrawText(
fmt.ctprintf("%r", s.text[char_index]),
s.column,
i32(y_pos),
CHAR_SIZE,
color,
)
// Occasionally glitch a character
if rand.int31_max(1000) < 5 {
s.text[i] = random_character()
}
}
// Reset streamer if it's gone off screen
if s.position * f32(CHAR_SIZE) - f32(len(s.text) * CHAR_SIZE) >= f32(SCREEN_HEIGHT) {
prepare_streamer(&s)
}
}
}
}