It really never ceases to amaze me the things you can do in JavaSCript. That's the kind of thing that up until a few years ago you'd be hesitant to do in Java. This is really cool stuff! I look forward to when we get full powered PC games done in JS. We're not there yet, I know - but it's little steps like this that'll get us there.
There's nothing particularly hard about this, or special about javascript though. This is the kind of stuff you could've implemented back in the day and ran on a Pentium MMX. It's about having an efficient algorithm.
I agree, the speeds you can achieve with JavaScript are astounding. They are far superior to Python, it's a shame JS doesn't have that well of a support for scientific calculations.
Just a side note: Java used to be slow, but is actually a lot lot faster now. So while javascript is certainly impressively fast, Java is actually even faster still.
It doesn't calculate all beams that originate from one point. It calculates only the beams which originate from one of the points and eventually reach the other point. It only looks random because the walls are placed at odd angles.
(use shift+click to move the light source)
https://github.com/scanlime/zenphoton