// ray-tracer: dictionary version: / scene, ray, hit S:{.+(`c`r;(x;y))} R:{.+(`o`d;(x;y))} H:{.+(`l`n;(x;y))} / unit vector Uv:{x*%_sqrt _dot[x]x} / ray_sphere Rs:{[r;s]:[0>d:(s.r*s.r)+(b*b:_dot[v]r.d)-_dot[v]v:s.c-r.o;0i;0>t:b+e:_sqrt d;0i;0Rs[r;*o];h;h _f[r]/o 1];~h.l>l:Rs[r]o;h;H[l]Uv r.o+(l*r.d)-o.c]} / ray_trace Rt:{[D;I;l;r;o]:[0i=(h:It[r;I]o)`l;0.;~0>g:_dot[h.n]l;0.;0i=It[R[r.o+(h.l*r.d)+D*h.n;-l];I;o]`l;-g;0.]} / create scene Sc:{[k;c;r]:[k=1;S[c]r;(S[c]r*3;sc[k;c;r;3*r%_sqrt 12],S[c]r)]} sc:{[k;c;r;s]{Sc[k-1;c+x,s,y]r%2}.'s*+-1 1@2 2_vs!4} / main Tr:{[k;n]p5[n]@,/m tr[_sqrt 2^-42;H[0i]0 0 0.;n*1.;Sc[k;0 -1 0.]1.;Uv -1 -3 2.]\:/:|m:!n} p5:{[n;g]"P5\n",($n)," ",($n),"\n255\n",_ci _.5+15.9375*g} tr:{[D;I;n;o;l;i;j]+//(!4){Rt[D;I;l;R[0 0 -4.]Uv((i,j)+(.25*x,y)-n%2),n]o}/:\:!4}