Get the latest tech news

Code golfing a tiny demo using maths and a pinch of insanity


A few weeks ago, I made a tiny demo that fits into 464 characters: void main(){vec3 c,p,K=vec3(3,1,0);for(float i,a,g=1.,t,h,d,w,k=.15;i++<1e2;d= max(max(d-3.,-d),0.)*k,w=g-g*exp(-mix(h*3e2,d*2.5,a=h<.001?0.:1.)),g-=w*a,c+=w* a*d*9.+(d==0.?K*.01*h:c-c),a=min(p.y+2.,1.),c.r+=w*a*a*.2,t+=min(h*.2,k*=1.015) ,p=normalize(vec3(P+P-R,R.y))*t,p.xz*=mat2(cos(sin(T*.2)+K.zyxz*11.)),p.z+=T*.3 )for(d=p.y,h=d+.5,a=.01;a<1.;a+=a)p.xz*=mat2(8,6,-6,8)*.1,d+=abs(dot(sin((p/a+T )*.3),p/p))*a,h+=abs(dot(sin(p.xz*.6/a),P/P))*a;O=vec4(tanh(c*.5),1);} There is no texture, no mesh, no 3D helper: it's simply a procedural mathematical formula evaluated at each pixel assigning them a color. Code golfing is about making it as short as possible, and thus is part of the art performance.

None

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Code

Code

Photo of pinch

pinch

Photo of maths

maths

Related news:

News photo

Big Tech Told Kids to Code. The Jobs Didn’t Follow [audio]

News photo

Fs-code – PyFilesystems for Gitlab, GitHub, and Git

News photo

Bringing Observability to Claude Code: OpenTelemetry in Action