-- util: math, screen & text helpers function lerp(a,b,t) return a+(b-a)*t end function eio(t) return t*t*(3-2*t) end function clmp(t) return mid(0,t,1) end function appr(v,t,a) return v>t and max(v-a,t) or min(v+a,t) end -- axis-aligned overlap: point (ax,ay) within (r,s) of point (bx,by) function ov(ax,ay,bx,by,r,s) return abs(ax-bx) arithmetic-on-nil crash). fillp(fadep[mid(1,flr(step),5)]+0x0.8) rectfill(0,0,127,127,0) fillp() end -- ember dissolve: the black cover burns away left->right, shedding embers off the -- wavy burn front. e=0 full cover -> e=1 clear. reuses the flame palette (fcol). function wipe(e) for i=0,127 do local x=191*e-32+sin(i*0.2)*12 rectfill(x,i,127,i,0) pset(x-rnd(12),i,fcol(rnd(1))) end end function pal2(c) pal(12,c) pal(13,c) end function skin_pal() local s=sk_c[bf_skin+1] if s[1]~=12 then pal(12,s[1]) pal(13,s[2]) end end function gbox(a,b,c,d) fillp(0x5a5a.8) rectfill(a,b,c,d,5) fillp() end -- dithered glow box function fcol(f) return f<0.3 and 7 or f<0.55 and 10 or f<0.8 and 9 or 8 end function bcol(f) return f<0.3 and 1 or f<0.8 and 12 or 7 end function fmt_time(s) return (s\60)..":"..(s%60<10 and "0" or "")..(s%60) end function pr_c(s,x,y,c) print(s,x-#s*2,y,c) end function pso(s,x,y,c) print(s,x+1,y+1,0) print(s,x,y,c) end function ptc(s,x,y,c,oc) print(s,x-#s*2+1,y+1,oc or 1) print(s,x-#s*2,y,c) end function bf_sx(sp) return bfly_seq[flr(t()*sp)%4+1]*8 end function bf_idx(sp) return bfly_seq[flr(t()*sp)%4+1] end