-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.lua
More file actions
40 lines (33 loc) · 1002 Bytes
/
main.lua
File metadata and controls
40 lines (33 loc) · 1002 Bytes
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
local curDetail = 1
lines = display.newGroup()
function drawLightning(x1, y1, x2, y2, displace, r, g, b)
if displace < curDetail then
--glow around lightning
for i = 1, 4 do
line = display.newLine(x1, y1, x2, y2)
line:setColor(r, g, b)
line.width = 20 / i
line.alpha = 0.05 * i
lines:insert(line)
end
--bolt itself
line = display.newLine(x1, y1, x2, y2)
line:setColor(r, g, b)
line.width = 2
lines:insert(line)
else
local midx = (x2+x1)/2
local midy = (y2+y1)/2
midx = midx + (math.random(0, 1) - 0.5)*displace
midy = midy + (math.random(0, 1) - 0.5)*displace
drawLightning(x1, y1, midx, midy, displace/2, r, g, b)
drawLightning(x2, y2, midx, midy, displace/2, r, g, b)
end
end
local function ontouch(e)
if e.phase == 'began' then
drawLightning(0, 0, e.x, e.y, 100, 255, 255, 255)
timer.performWithDelay(500, function() display.getCurrentStage():remove(1); lines = display.newGroup() end)
end
end
Runtime:addEventListener('touch', ontouch)