-
Notifications
You must be signed in to change notification settings - Fork 4
/
DanceFloor.txt
84 lines (74 loc) · 2.18 KB
/
DanceFloor.txt
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
--@name DanceFloor
--@author Sparky
--@shared
if SERVER then
wire.adjustInputs({"BPM"},{"normal"})
hook.add("input","",function(k,v)
if k=="BPM" and v then
net.start("BPM")
net.writeDouble(v)
net.send()
end
end)
else
local function mix(a,b,t)
return (b-a)*t+a
end
local function hash(x)
return (math.sin(x*127.1)*43758.5453123)%1
end
local function noise(x)
local fx = x%1
local ix = x-fx
return mix( hash( ix ), hash( ix+1 ), fx*fx*(3-2*fx))
end
local squaresize = 1024/8
local start = 0
local endsize = 1024-squaresize
local squaresize2 = squaresize/2
local start2 = endsize/2-squaresize2
local endsize2 = endsize/2+squaresize
local freq = 2
local lights = setmetatable({},{__index=function(t,k) t[k]=light.create(Vector(),300,5,Color(0,0,0)) return t[k] end})
local scr = chip()
render.createRenderTarget("floor")
hook.add("render","",function()
scr = render.getScreenEntity()
render.setRenderTargetTexture("floor")
render.drawTexturedRectFast(0,0,512,512)
end)
hook.add("renderoffscreen","",function()
render.selectRenderTarget("floor")
local time = timer.curtime()*freq
local i = 1
for x=start, endsize, squaresize do
for y=start, endsize, squaresize do
local z = noise(i*100+time)
local col = Color(z*70+250,0.8,0.8):hsvToRGB()
render.setColor(col)
render.drawRectFast(x, y, squaresize, squaresize)
i = i + 1
if i%4==0 then
local wpos = scr:localToWorld(Vector((x+squaresize2-512)/512*189.791, (y+squaresize2-512)/512*189.791, 2))
lights[i]:setPos(wpos)
lights[i]:setColor(col)
lights[i]:draw()
end
end
end
for x=start2, endsize2, squaresize2 do
for y=start2, endsize2, squaresize2 do
local z = noise(i*100+time)
render.setColor(Color(z*70,0.8,0.8):hsvToRGB())
render.drawRectFast(x, y, squaresize2, squaresize2)
i = i + 1
end
end
render.selectRenderTarget()
end)
hook.add("net","",function(n)
if n=="BPM" then
freq = net.readDouble()/60
end
end)
end