r/GraphicsProgramming • u/Character_Trick460 • Oct 15 '26
Source Code Very primitive raycasting renderer in 10 lines of C
Actually the raycasting logic itself is just a single line, but it's done in propably the most inefficient way possible.
The map is just a single 64 bit integer, so I could fit a small 8x8 level in it, and I can index it with some unorthodox bitshift magic.
Also all the integer constants are huge, because I wanted do to the whole thing without floating point math, which makes everything even more unreadable, but at least it's funny ig.
I'm very proud of this one.
193
Upvotes


9
u/Slackluster Oct 15 '26
nice! welcome to the world of size coding. it's a super fun type of recreational programming.
your code is good start but there is room to make it smaller. i recommend checking into the demo community and places like dwitter.net that have some great ideas for this kind of thing.
heres my JavaScript raycasting one liner...
https://www.dwitter.net/d/34603
6
u/GaboureySidibe Oct 15 '26
Very cool. Any simple explanation you can give? Is the outer loop going through the horizontal line and the two inner loops are drawing vertically?
90
u/UntitledRedditUser Oct 15 '26
Equally impressive as it is unreadable
43
u/grady_vuckovic Oct 15 '26
Vibe coders be like 'Code isn't art!'.
I disagree and I think this is a lovely example of how code itself can be beautiful.
6
u/PictureNew661 Oct 15 '26
Very very impressive
3
u/Eastern-Bed-3103 Oct 15 '26
I feel like we may be disregarding the concept of a line here, but - nonetheless - very impressive. :D
1
u/TryEdgeTech 25d ago
I find the process of thorough optimization to be truly fascinating.
1
u/simonsanchezart Oct 15 '26
can't this just be one line?
1
u/eltomiros Oct 16 '26
the GOAT
1
u/BeastMsterThing2022 Oct 16 '26
This is beautiful!
1
u/MushroomSaute Oct 16 '26
You could shorten that to 1 line easily
-7
u/garma87 Oct 15 '26 edited Oct 15 '26
At least provide an image that it would produce. You provided some gif but it’s very unclear to me what that shows
Sorry to dump on your parade but I’ve just never seen the point of making code that is so unreadable. Doing a lot in very little code is impressive sure, but obfuscating it like this just makes it impossible to follow. Just post the assembly then if readability is irrelevant
-5
u/tlmbot Oct 15 '26
That is wild. Nice one OP!
I'd feed it to Claude and see if it can figure out what this code does.
(Am I dumb for not being certain that Claude would instantly figure out that it's raycasting ascii integer voodoo?)
I mean, I think Claude probably would get it right, but it seems like a fun check.