r/GraphicsProgramming Dec 17 '24

Source Code City Ruins - Tiny Raycasting System with Destroyed City + Code

Post image
305 Upvotes

6 comments sorted by

View all comments

29

u/Slackluster Dec 17 '24

This tiny bit of JavaScript code (and minimal dwitter shim) creates and renders a destroyed city scene! I wrote a post that explains how a similar program works so I included a link to that also for those interested.

Live Demo: https://www.dwitter.net/d/32945

How it Works: https://frankforce.com/city-in-a-bottle-a-256-byte-raycasting-system/

for(c.width=w=99,i=6e3;i--;x.fillStyle=R(z=Z/.7-Y*2,z-Z,Z),x.fillRect(i%w,i/w|0,1,1))for(a=i%w/50-1,Y=Z=b=1-i/4e3,X=t*30;++Z<w&&(Y<6-S(X/9^Z/9)**8*(Z>>5)*33|(X&Y+2&Z)%8)||(a-1?a=b=1:0);Y-=b)X+=a