

Smallpt: Global Illumination in 99 lines of C++ (with no external deps) - benhoyt
http://www.kevinbeason.com/smallpt/

======
jcl
I love that they modeled the walls of the room with giant spheres... a
wonderful hack to avoid having to support plane primitives while still
producing something that looks like a Cornell box.

------
profquail
GPU Version: <http://davibu.interfree.it/opencl/smallptgpu/smallptGPU.html>

------
adamtj
It could be 1 line. sloc doesn't mean much for C++ unless the code is sanely
formatted. E.g. an if/else should be at least 2 lines, usually 4.

Edit: That said, I'm still impressed.

~~~
houseabsolute
This is a sight more readable than some much more sanely formatted C++
programs I've read. What I've learned from this that it's often the simplicity
of the program that's more important than the formatting. (Although formatting
is of course still important and anyone who inflicts code like this on their
coworkers doesn't reach my standard of "decent human being.")

------
jrockway
Readable!

------
lutorm
Nice. Though all of the 99 lines are >75 characters. With a more readable
formatting it would be twice as long... ;-)

~~~
miratom
Yes, this would be tons more philanthropic and if it were just readable. Just
some simple line breaks and variable names that meant something. It's not
impressive that you can just cram stuff into 99 lines.

~~~
yason
Actually, the code seemed to be a mess but was quite readable. I read it
through. You could almost see all the code in once glance which is when you
pretty much don't need formatting anymore, just some time to initially absorb
the code.

------
palish
I wish the source code was cross-platform. It doesn't build in Visual Studio.

    
    
      'erand48': identifier not found
      'M_PI' : undeclared identifier
    

Obviously #define M_PI 3.1415926 should do the trick, but I need to track down
an erand48 replacement.

~~~
romland
Might want to check out:
<http://gnuwin32.sourceforge.net/packages/libgw32c.htm>

Or the FreeBSD source:
[http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/gen/erand...](http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/gen/erand48.c?rev=1.2)

