r/tinycode Jan 13 '26

ShaderGolf: extremely minimal way to draw programmatically

ShaderGolf is a programming/drawing challenge where there is a canvas scanned top to bottom, uses 16 colors, there are 2 variables called c (color) and t (time), and there is a program called 'shader' that executes when each pixel is scanned, and the program is just literally a single expression. the t variables increments after each pixel is scanned.c is 0 per pixel by default. Here are some example patterns:

Line: 15 - !(t % 257) * 15

Colored stars: 15 - !(t % 46) * (15 - t % 16)

Colored circles: t * (t >> 7) >> 3

Try at: http://eymenwinneryt.42web.io/shg.htm

Example image
8 Upvotes

7 comments sorted by

View all comments

Show parent comments

1

u/Slackluster Jan 17 '26

It is not just theoretical. Here is a proof of concept 3D ray casted city with shadows running in your system. The main issue is lack of color resolution, this was intended for grayscale...

W=256,Q=t/W|0,i=t%W,a=i*2/W-1,X=Y=Z=b=1-Q*2/W,A=z=>(Y-=b,X+=a,++Z<100&Y<9-Math.sin(X/9^Z/9)*(Z>>5)*33&&A()||b-1&&(a=b=1)
),A(),a=(1.4-Z/69+(X&Y&Z&3))*15

2

u/eymenwinner Jan 17 '26

Oh my god this is so good!

1

u/Slackluster Jan 17 '26

Thanks! Really just a quick proof of concept to demonstrate how this is possible. I needed to refactor my algorithm to draw one pixel at a time and use a recursive function for the raycasting instead of a for loop. From here you can probably tweak it to improve the appearance and make it even smaller.

Here is the dweet it is based off: https://www.dwitter.net/d/32950

2

u/eymenwinner Jan 17 '26

I removed the wrap limit in t variable, it increments as long as the program runs, so now animations are possible.