# I wrote a ray tracer in Brainfuck

> Hacker News story 49842409 · language: en · submitted 2026-09-25
> Web version: https://zeli.app/story/49842409
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 90 · by [epestr](<https://news.ycombinator.com/user?id=epestr>) · 💬 21
[original](<https://epestr.com/blog/writing-a-ray-tracer-in-brainfuck/>) · [HN discussion](<https://news.ycombinator.com/item?id=49842409>)

## Summary

After noticing a CMake tutorial mention that ray-tracers had been written in CMake, I decided to write one in Brainfuck. I implemented fixed-point arithmetic (Q16.16), square root via long division, and a pseudo-random generator. The resulting 23MB program renders a 400x225 image at one pixel per minute, proving that a simple language doesn't guarantee a simple codebase.

## Key quote

> The program was finally 23MB, which is larger than the image itself [which was about 0.9MB], which makes it a rather poor choice for a compression technique.

## HN discussion (21 comments)

### [throwaway99e2](<https://news.ycombinator.com/item?id=49843377>)

> 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](<https://news.ycombinator.com/item?id=49850887>)

> 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 […]

---

## Cite

- Page: https://zeli.app/story/49842409
- Date: 2026-09-25
- Source: epestr.com (https://epestr.com/blog/writing-a-ray-tracer-in-brainfuck/)
- Hacker News: https://news.ycombinator.com/item?id=49842409

## Other languages

- zh: https://zeli.app/zh/story/49842409 · markdown: https://zeli.app/zh/story/49842409.md
- ja: https://zeli.app/ja/story/49842409 · markdown: https://zeli.app/ja/story/49842409.md
- ko: https://zeli.app/ko/story/49842409 · markdown: https://zeli.app/ko/story/49842409.md
- de: https://zeli.app/de/story/49842409 · markdown: https://zeli.app/de/story/49842409.md
- es: https://zeli.app/es/story/49842409 · markdown: https://zeli.app/es/story/49842409.md
- ru: https://zeli.app/ru/story/49842409 · markdown: https://zeli.app/ru/story/49842409.md
