I know this isn't the best way to do it, but I thought I'd post my attempt anyway
It works, but if there are too many points it lags like crazy ( Granted, my computer is rather bad, but still) And even so, if you use too few points ( less than 360 / ( 36 / 4)) it will clip the shape too much, and glitch out.
Based on your last post, you have modifiable sizes, I'm sure that wouldn't be too hard for you too add to this system, though I'm using fixed light sizes.
this.lightSize modifies the size,
this.shapeIncrease modifies how many points are on the shape
this.shapeCheck modifies how far it checks in deviation to a point, before deciding it's clipping one too close already
this.lightSources is the array of objects, currently it's adding all players in the level as a light source... so don't try this in a populated level.. lol..
near the bottom you find an f for below it there's
PHP Code:
if ( f > 7 && !temp.searchNextPoint)
that check tells how close a point needs to be, before the script decides the next point it does locate, is actually from another source ( this makes it so diffrent light sources don't clip together unless they're close enough)
the incriments to the f for alter how fast it spreads outwards, in attempt to locate the next point.
The system first locates the closest light to the top left of the level, then it locates each point of that light, by determining which point is closest to the one it's at, without being the last. If a light point is too far from the last, it decides it's another light source and marks that to be a seamless return point, so that the polygon doesn't reclip itself when it returns.
All in all, I'm sure there's a much better way of going about this.
I was going to paste it under CODE or PHP tags, but apparently the server doesn't understand when I try to paste too much or something.. I'll just use attachments