I’m working on what isn’t so much lighting as it is a way to make a field of view where a character can’t see through walls in a 2D game. This is the first test of it (didn’t even have time to test or fix any code) but it is functional.

```
--# Main
function setup()
attempt = physics.rect(1,1)
attempt2 = physics.rect(1,1)
light = Lights(vec2(WIDTH/2,HEIGHT/2),{attempt,attempt2})
frame = 0
rectMode(CENTER)
physics.gravity(0,0)
end
function draw()
background(255, 255, 255, 255)
fill(0, 0, 0, 255)
rect(attempt.position.x+1,attempt.position.y+1,51)
rect(attempt2.position.x+1,attempt2.position.y+1,51)
ellipse(WIDTH/2,HEIGHT/2,10)
light:draw()
end
function touched(t)
attempt.position = vec2(t.x,t.y)
attempt.linearVelocity = vec2(0,0)
attempt2.position = vec2(WIDTH-t.x,HEIGHT-t.y)
attempt2.linearVelocity = vec2(0,0)
end
physics.rect = function(x,y,w,h)
x = x or WIDTH/2
y = y or HEIGHT/2
w = w or 50
h = h or 50
return physics.body(POLYGON,
vec2(x-w/2,y-h/2),vec2(x+w/2,y-h/2),
vec2(x+w/2,y+h/2),vec2(x-w/2,y+h/2))
end
--# Lights
Lights = class()
displayMode(FULLSCREEN)
function Lights:init(center,bodies)
self.p = center
self.b = bodies
self.edges =
{physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT)),
physics.body(EDGE,vec2(0,0),vec2(WIDTH,0)),
physics.body(EDGE,vec2(WIDTH,HEIGHT),vec2(0,HEIGHT)),
physics.body(EDGE,vec2(WIDTH,HEIGHT),vec2(WIDTH,0))}
for i,v in ipairs(self.edges) do
v.mask = {1}
end
self.mesh = mesh()
end
function Lights:draw()
local b = self.p
local verts = {}
for i,v in pairs(self.b) do
local points = {}
for j,z in pairs(self.b[i].points) do
local z2 = z + v.position
local m1 = (z2.y-b.y)
local m2 = (z2.x-b.x)
local dx = math.abs(WIDTH/m2)
local dy = math.abs(HEIGHT/m1)
local q = vec2((b.x+m2*50),(b.y+m1*50))
table.insert(points,{z2,q})--ep.point})
end
if #points>3 then
for i=1,#points/2 do
local a = points[i]
local b = points[i+2]
local tri=triangulate({a[1],a[2],b[2],b[1]})
for i=1,#tri do
verts[#verts+1] = tri[i]
end
end
self.mesh.vertices = verts
self.mesh:setColors(0,0,0,255)
end
end
self.mesh:draw()
self.mesh:clear()
end
```

Comments and suggestions are welcome