Skip to content

Instantly share code, notes, and snippets.

@mrange
Last active September 23, 2023 12:08
Show Gist options
  • Save mrange/189679ddefcc276d384c52a42b022846 to your computer and use it in GitHub Desktop.
Save mrange/189679ddefcc276d384c52a42b022846 to your computer and use it in GitHub Desktop.
My first TIC-80 program
function clamp(value, min, max)
return math.min(math.max(value, min), max)
end
function mix(a,b,x)
return a+(b-a)*x
end
function pmin(a,b,k)
local h = clamp(0.5+0.5*(b-a)/k, 0.0, 1.0)
return mix(b, a, h) - k*h*(1.0-h)
end
function TIC()
local t = time()
for x = 0, 239 do
for y = 0, 135 do
local qx = x/240
local qy = y/136
local px = -1+2*qx
local py = -1+2*qy
px = px*240/136
local d = 1000
for i = 0, 2 do
local ppx = px
local ppy = py
local tt = t+i*1023
ppx = ppx+math.sin(0.001*tt)
ppy = ppy+math.sin(0.00213*tt)
local dd = ppx*ppx+ppy*ppy
dd = math.sqrt(dd)
d = pmin(d, dd, 0.5)
end
pix(x,y,(-0.01*t+d*10)%16)
pix(x,y,(-0.01*t+d*10)%16)
end
end
local lx = 80+40*math.sin(t*0.001)
local ly = 64+40*math.sin(t*0.001234)
print("Impulse 2023", lx+1, ly+1, 0)
print("Impulse 2023", lx, ly, (0.5*t)%16)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment