The author undertook the project while preparing for a C++ systems programming competition, motivated by a desire to find an even more constrained language than CMake for implementing build tools. They chose to recreate the exact scene from the 'Metal' chapter of the popular 'Ray Tracing in One Weekend' tutorial as their target output, using Brainfuck's eight simple commands that manipulate a data pointer and byte-sized memory cells.
To achieve this within Brainfuck's constraints, the author had to implement all necessary mathematical operations from the ground up. Since Brainfuck operates only on bytes and lacks native support for arithmetic beyond increment/decrement, they developed a custom fixed-point number representation using the Q16.16 format. This allocates 16 bits for integer precision and 16 bits for fractional precision, providing sufficient range and accuracy for the ray tracing calculations. They also constructed implementations of essential mathematical functions including square root (using a long-division method after rejecting Heron's formula due to its division requirements) and a pseudorandom number generator based on a simple linear congruential formula (A = (5A+1) mod 256) suitable for supersampling anti-aliasing.
The resulting Brainfuck program exhibits the expected trade-offs of such extreme language constraints. Weighing in at 23MB, the program is massive compared to conventional implementations, reflecting the enormous amount of code needed to express simple operations in Brainfuck's primitive instruction set. Performance is correspondingly slow: the author measured approximately 100 ray calculations per minute, equating to roughly one pixel rendered per minute. At this rate, completing the full 400x225 pixel image (90,000 total pixels) would require about 62.5 days of continuous computation on their laptop, though they noted that the computational complexity of ray-sphere intersections would likely extend this estimate further. Despite these limitations, the output shows remarkable fidelity to the reference implementation. After generating 1,229 pixels, only 10 differed from the reference C implementation, and those differences were mostly by a value of just 1 in the color channels. The author observed that the Brainfuck-rendered image has a distinctive visual quality reminiscent of a Van Gogh painting, which they attribute to accumulated precision errors from the fixed-point arithmetic and mathematical approximations.

Shows the reference C implementation output for comparison with the Brainfuck version, as discussed in the paragraph about fidelity.

Shows the Brainfuck-rendered output, which exhibits a Van Gogh-like visual quality due to precision errors from fixed-point arithmetic.