I wrote a ray tracer in Brainfuck
epestr
58 points
14 comments
September 25, 2026
Related Discussions
Found 5 related stories in 92.7ms across 7,702 title embeddings via pgvector HNSW
- Implementing the esoteric "Brainfuck" language in Carp Lisp [video] Bluestein · 25 pts · September 22, 2026 · 57% similar
- 56,000 lines of DOOM, in a language I made up ghuntley · 36 pts · July 16, 2026 · 45% similar
- Software rendering in 500 lines of bare C++ mpweiher · 269 pts · July 23, 2026 · 44% similar
- Show HN: Watch 14-Byte AI "brains" attempt to solve a 2D maze (Its hard) purple-leafy · 23 pts · July 27, 2026 · 43% similar
- RayforceDB – a pure C analytics database with a Lisp-like syntax sourdecor · 32 pts · August 14, 2026 · 41% similar
Discussion Highlights (5 comments)
blanchebiche
Calling this "written in brainfuck" is like calling anything in C "written in machine code"
throwaway99e2
Isn't this just a ray tracer in python/c that spits out brainfuck? By this logic gcc writes all my programs in assembly lol
shoo
brainfuck is unpleasant to write directly - e.g. the language doesn't have variables, so you need to manually do the bookkeeping of which memory offset is storing what 'variable'. & if you need to refactor your program slightly, in a way that changes the memory layout, maybe you need to manually rework the absolute & relative offsets. So I can appreciate why the author didn't roll up their sleeves to directly write BF - that's neither a productive nor interesting exercise. Interesting to see how the author decomposed the problem: - C raytracer https://github.com/mTvare6/rayfuck/blob/master/ray.c ~~ LLM refactor of the C code ~~> - SSA-style C raytracer code https://github.com/mTvare6/rayfuck/blob/master/ray_ssa.c ~~ c2dsl.py helper script (compiler) ~~> - DSL raytracer https://github.com/mTvare6/rayfuck/blob/master/ray.dsl ~~ dsl2bf.py helper script (another compiler) ~~> BF raytracer https://github.com/mTvare6/rayfuck/blob/master/ray.bf (~22 mb of unreadable nonsense) The dsl2bf compiler has a bunch of examples of implementing slightly higher level abstractions atop BF primitives. E.g. "go" to move the pointer to a different offset, destructive & non-destructive copies, all the way up to things like division -- BF only natively offers unary addition/subtraction. If we have a read of the code of the final compiler, dsl2bf.py, the abstractions used in that code are relatively simple: global variables, local variables, lists, dicts, for loops, function definitions & function calls. It is feasible to implement a simple compiler like dsl2bf in BF itself, with sufficient head scratching. Again, quite unpleasant to try it directly in BF, but a next step could be to implement the dsl2bf compiler in the DSL itself - extending it if necessary, then compiling it with itself to produce a dsl2bf compiler implemented in BF.
laughing_man
I'm kind of disappointed nobody writes this kind of stuff in Whitespace.
extraduder_ire
There have been some other attempts to build compilers that output brainfuck. This one supports some LLVM IR instructions: https://github.com/caozhanhao/llvm-brainfuck There's a list of others here, with asm2bf seeming the most complete: https://esolangs.org/wiki/Brainfuck_code_generation