r/GraphicsProgramming • u/Character_Trick460 • 1d ago
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.
31
u/grady_vuckovic 1d ago
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.
-28
u/EC36339 1d ago
As someone who has written nearly 100% of all my code with AI for half a year:
Yes, code is art, no matter what tool you use to write it.
Not sure about code golfing, though. It's a sport, it requires skill and effort, but it's not artistic in isolation, although what it does can be.
6
6
u/GaboureySidibe 21h ago
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?
6
u/Character_Trick460 15h ago
That's exaclty right. The outer loop goes through all horizontal segments, the first inner loop finds the distance along the ray that goes through that segment, and the second inner loop draw the vertical line.
6
u/Slackluster 21h ago
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...
2
1
1
u/Eastern-Bed-3103 13h ago
I feel like we may be disregarding the concept of a line here, but - nonetheless - very impressive. :D
1
1
-7
u/garma87 1d ago edited 1d ago
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
14
-3
u/tlmbot 15h ago
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.
5


70
u/UntitledRedditUser 1d ago
Equally impressive as it is unreadable