3 ms·
7 lines of K: http://www.nsl.com/k/ray/raya.k http://www.nsl.com/k/ray/raya.k
by foxfluff 5y ago
7 lines of K: http://www.nsl.com/k/ray/raya.k http://www.nsl.com/k/ray/raya.k
- kragen 5y agoNice! APL-family languages are really great at this kind of thing; I should see how small I can squinch a raytracer with just NumPy. Stevan Apter's programs (like that one) constantly make me wish I knew K: even if I don't want my code to look like that, it seems like it would be great to be able to type it in that way. That also leads to a one-page OCaml version and a two-page C++ version by Jon D. Harrop (the Flying Frog guy), both also using PPM output and rendering only spheres, much like most of my examples: https://web.archive.org/web/20070605173709/http://www.ffconsultancy.com/languages/ray_tracer/comparison.html https://web.archive.org/web/20070605173709/http://www.ffcons... He also wrote an SML version https://web.archive.org/web/20070522030632/http://www.ffconsultancy.com/languages/ray_tracer/comparison_cpp_vs_sml.html https://web.archive.org/web/20070522030632/http://www.ffcons... and a Java version, and others ported it to Scheme and Common Lisp https://web.archive.org/web/20070515185350/http://www.ffconsultancy.com/languages/ray_tracer/benchmark.html https://web.archive.org/web/20070515185350/http://www.ffcons..., those these seem to be lost now. Still others ported it to Io http://mike-austin.com/io/ray.io http://mike-austin.com/io/ray.io and Factor https://github.com/factor/factor/blob/master/extra/benchmark/raytracer/raytracer.factor https://github.com/factor/factor/blob/master/extra/benchmark... (3 pages). In https://www.pouet.net/prod.php?which=83222 https://www.pouet.net/prod.php?which=83222 Holtsetio wrote a raytracer in two pages of MySQL SQL, but it's sort of obfuscated. It emits the output in BMP format (almost as simple as PPM) and uses lots of imperative MySQL extensions to SQL, and it ended up as 10 KiB instead of the 1 KiB of my Clojure version. But it handles triangles, not just spheres, so it can render the Stanford bunny. https://github.com/chunky/sqlraytracer/blob/master/raytracer.sql https://github.com/chunky/sqlraytracer/blob/master/raytracer... is instead about three pages of SQL, using recursive CTEs instead of imperative assignments, and supporting only spheres but with different materials, like my C version. He's using recursive CTEs as implemented in Postgres: compliant with ANSI SQL but not implemented in most other SQL engines. In particular, he started out with SQLite but it wasn't strong enough.
- mzeeshan7929 5y ago[flagged]
- progre 5y agoIs it fair to think of programming in K as directly writing bytecode for an array VM?
- ithkuil 5y agoNo EDIT: it may look gibberish but it's still a structured source file, that requires (simple) lexical analysis etc