forked from Sevii77/starfall_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_rain.lua
75 lines (59 loc) · 1.41 KB
/
matrix_rain.lua
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
--@name Matrix Rain
--@author Sevii
--@client
local size = 8
local fall_mul = 4
local decay_mul = 4
local frequency = 20
local color = Color(0, 255, 65)
----------------------------------------
local time = 0
local delay = 1 / frequency
local droplets = {}
local font = render.createFont("Roboto Mono", size)
render.createRenderTarget("")
hook.add("render", "", function()
local delta = timer.frametime()
-- Spawn new droplets
time = time - delta
while time <= 0 do
time = time + delay
table.insert(droplets, {
x = math.random(0, 512 / size),
y = 0
})
end
-- Handle droplets
render.selectRenderTarget("")
render.setColor(color)
render.setFont(font)
render.setFilterMin(1)
render.setFilterMag(1)
local drop = delta * fall_mul
local new = {}
for _, droplet in pairs(droplets) do
local y = droplet.y + drop
if y < 512 / size then
local yr = math.round(y)
local char = droplet.char
if yr ~= droplet.yr then
char = string.char(math.random(34, 128))
end
table.insert(new, {
x = droplet.x,
y = y,
yr = yr,
char = char
})
render.drawSimpleText(droplet.x * size, yr * size, char)
end
end
droplets = new
-- RT
render.setRGBA(0, 0, 0, delta * decay_mul * 255)
render.drawRect(0, 0, 1024, 1024)
render.selectRenderTarget()
render.setRenderTargetTexture("")
render.setRGBA(255, 255, 255, 255)
render.drawTexturedRect(0, 0, 1024, 1024)
end)