Skip to content

Instantly share code, notes, and snippets.

@shuuki
Created December 15, 2016 04:20
Show Gist options
  • Save shuuki/2a9c450bdc7ccd41e7d0d91cf0a80bf4 to your computer and use it in GitHub Desktop.
Save shuuki/2a9c450bdc7ccd41e7d0d91cf0a80bf4 to your computer and use it in GitHub Desktop.
-- orbital composite
-- @mzxio
-- constants ------------------
pi = 3.14159
rad = 2 * pi
-- data -----------------------
-- sun
sun = {}
sun.p = 24
sun.ox, sun.oy = 64, 64
sun.sw, sun.sh = 60, 30
-- moon
moon = {}
moon.p = 648
moon.ox, moon.oy = 64, 64
moon.sw, moon.sh = 60, 30
moon.l = {
'new',
'crescent',
'first quarter',
'gibbous',
'full',
'disseminating',
'last quarter',
'balsamic'
}
-- season
season = {}
season.p = 8760
season.l = {
'spring',
'summer',
'autumn',
'winter'
}
-- math -----------------------
-- ceiling
function ceil (x)
return -flr(-x)
end
-- rounding
function round (x)
local r = abs(x - flr(x))
if r >= 0.5 then
return ceil(x)
else
return flr(x)
end
end
-- angle between points
function pang(x1,y1, x2,y2)
local x = x2 - x1
local y = y2 - y1
local ang = atan2(y, x)
return ang
end
-- distance between points
function plen (x1,y1, x2,y2)
local x = (x2 - x1)^2
local y = (y2 - y1)^2
local len = sqrt(y + x)
return len
end
-- polar to coord
function ptoc (len, ang)
local con = {}
con.x = len * cos(ang)
con.y = len * sin(ang)
return con
end
-- attenuation
function attn(pow, dist)
local att = pow / (dist^2)
return att
end
-- periodicity
function per (x, p)
return (x % p) / p
end
-- logic ----------------------
-- clocks
function clocks (t)
local clk = {}
clk.s = per(t, 1)
clk.m = per(t, 60)
clk.h = per(t, 3600)
return clk
end
-- phase calculator
function phase (t, b)
local p = per(t, b.p)
local i = ceil(p * #b.l)
return i
end
-- takes time, body object
-- returns index of phase
-- sky body position
function sbod (b, t)
local pos = {}
pos.x = b.ox + b.sw * cos(t)
pos.y = b.oy - b.sh * sin(t)
return pos
end
-- body object, theta 0-1
--print(sbod(sun,0.15).x)
-- game -----------------------
function inputs ()
if btn(4) then
mx = mx * 1.05
if (mx > 20) mx = 20
else
if (mx > 1) mx = mx * 0.95
--if (mx < 1) mx = 1
end
if btn(5) then
mx = mx / 1.08
end
life += mx
end
-- pico -----------------------
function _init ()
t = time()
spin = rnd(8760)
life = 0
mx = 0.1
vive = 50
end
function _update60 ()
t1 = time()
dt = t1 - t
t = t1
life += dt
inputs()
clk = clocks(life)
prec = 40 + sin(-per(life, 8760)) * 20
prec2 = sin(per(life, 8760))+3
sun.sh = prec
moon.sh = prec
dmx = phase(life, moon)
dsx = phase(life, season)
ssx = sbod(sun, per(life, 24))
ssm = sbod(moon,per(life, 25))
fool = pang(sun.ox,sun.oy,ssx.x,ssx.y)
doop = pang(moon.ox,moon.oy,ssm.x,ssm.y)
if fool < 0.25 then
vive = vive - rnd(10)/sun.sh
elseif fool < 0.5 then
vive = vive + rnd(10)/sun.sh
elseif fool < 0.75 then
vive = vive + rnd(10)/sun.sh
elseif fool < 1 then
vive = vive - rnd(10)/sun.sh
end
-- find period that gives moon
-- a 27 day cycle
-- relative to sun
end
function _draw ()
cls()
--print('life '..round(life))
--print(dmx..' '..dsx..' '..sun.sh)
--print('mult '..mx, 0,120)
--print(prec/20)
--print(round(vive))
--print(fool)
--print('s '..fool%1)
--print('m '..doop)
--print('nah '..fool-doop)
--line(0,60,128,60,13)
rectfill(0,61,128,128,1)
circfill(ssx.x, ssx.y, 1, 7)
circfill(ssm.x, ssm.y, 2, 13)
--print(prec2)
--pset(64, prec, 3)
--print(attn(1,prec2))
--line(64,64,ssx.x,ssx.y)
--line(64,64,ssm.x,ssm.y)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment