Something I’ve been messing around with. Touch the screen to generate a lightning effect. Satisfies your inner Palpatine!
-- Lightning Touch
displayMode(FULLSCREEN)
function setup()
target=vec2(WIDTH/2,HEIGHT/2)
generateArc()
showLightning=false
end
function draw()
-- This sets a dark background color
background(42, 42, 83, 255)
if showLightning then
for i,a in pairs(arc) do
if math.random(5)>1 then
--do nothing - leave the arc blank
else
local w=math.random(3)
strokeWidth(w*5)
stroke(102, 34, 129, 255)
line(a.s.x,a.s.y,a.a.x,a.a.y)
line(a.a.x,a.a.y,a.b.x,a.b.y)
line(a.b.x,a.b.y,target.x,target.y)
strokeWidth(w*3)
stroke(182, 0, 255, 255)
line(a.s.x,a.s.y,a.a.x,a.a.y)
line(a.a.x,a.a.y,a.b.x,a.b.y)
line(a.b.x,a.b.y,target.x,target.y)
strokeWidth(w)
stroke(255, 255, 255, 255)
line(a.s.x,a.s.y,a.a.x,a.a.y)
line(a.a.x,a.a.y,a.b.x,a.b.y)
line(a.b.x,a.b.y,target.x,target.y)
end
end
peturb()
stroke(182, 0, 255, 255)
fill(255)
ellipse(target.x,target.y,10+math.random(5))
end
end
function touched(t)
target.x=t.x
target.y=t.y
generateArc()
for i=1,25 do
peturb()
end
if t.state==BEGAN then
showLightning=true
elseif t.state==ENDED or t.state==CANCELLED then
showLightning=false
end
end
function peturb()
for i,a in pairs(arc) do
a.a.x=a.a.x+math.random(7)-4
a.a.y=a.a.y+math.random(7)-4
a.b.x=a.b.x+math.random(7)-4
a.b.y=a.b.y+math.random(7)-4
end
end
function generateArc()
arc={}
table.insert(arc,{s=vec2(0,0),a=vec2(target.x/3,target.y/3),b=vec2(2*target.x/3,2*target.y/3)})
table.insert(arc,{s=vec2(WIDTH,0),a=vec2(WIDTH-(WIDTH-target.x)/3,target.y/3),b=vec2(WIDTH-2*(WIDTH-target.x)/3,2*target.y/3)})
table.insert(arc,{s=vec2(0,HEIGHT),a=vec2(target.x/3,HEIGHT-(HEIGHT-target.y)/3),b=vec2(2*target.x/3,HEIGHT-2*(HEIGHT-target.y)/3)})
table.insert(arc,{s=vec2(WIDTH,HEIGHT),a=vec2(WIDTH-(WIDTH-target.x)/3,HEIGHT-(HEIGHT-target.y)/3),b=vec2(WIDTH-2*(WIDTH-target.x)/3,HEIGHT-2*(HEIGHT-target.y)/3)})
table.insert(arc,{s=vec2(WIDTH/2,0),a=vec2(WIDTH/2-(WIDTH/2-target.x)/3,target.y/3),b=vec2(WIDTH/2-2*((WIDTH/2-target.x)/3),2*target.y/3)})
table.insert(arc,{s=vec2(WIDTH/2,HEIGHT),a=vec2(WIDTH/2-(WIDTH/2-target.x)/3,HEIGHT-(HEIGHT-target.y)/3),b=vec2(WIDTH/2-2*((WIDTH/2-target.x)/3),HEIGHT-2*(HEIGHT-target.y)/3)})
table.insert(arc,{s=vec2(0,HEIGHT/2),a=vec2(target.x/3,HEIGHT/2-(HEIGHT/2-target.y)/3),b=vec2(2*target.x/3,HEIGHT/2-2*((HEIGHT/2-target.y)/3))})
table.insert(arc,{s=vec2(WIDTH,HEIGHT/2),a=vec2(WIDTH-(WIDTH-target.x)/3,HEIGHT/2-(HEIGHT/2-target.y)/3),b=vec2(WIDTH-2*(WIDTH-target.x)/3,HEIGHT/2-2*((HEIGHT/2-target.y)/3))})
end