function Spring.new(F,c,b)local D=c or 1 local W=b or 1 local e=F or 0 local V=0*e local J=e local v=V local R=tick()local z={}local u={}function z.getpv()return posvel(D,W,e,V,J,v,tick()-R)end function z.setpv(F,c)local b=tick()local D,W=targposvel(J,v,b-R)e,V=F,c J,v=D,W R=b end function z.settargetpv(F,c)local b=tick()local z,u=posvel(D,W,e,V,J,v,b-R)e,V=z,u J,v=F,c R=b end function z.accelerate(c,F)local b=tick()local z,u=posvel(D,W,e,V,J,v,b-R)local l,q=targposvel(J,v,b-R)e,V=z,u+F J,v=l,q R=b end function u.__index(F,c)local b=tick()if c=="\112"or c=="\112\111\115\105\116\105\111\110"then local F,c=posvel(D,W,e,V,J,v,b-R)return F elseif c=="\118"or c=="\118\101\108\111\099\105\116\121"then local F,c=posvel(D,W,e,V,J,v,b-R)return c elseif c=="\116\112"or c=="\116"or c=="\116\097\114\103\101\116\112\111\115\105\116\105\111\110"then local F,c=targposvel(J,v,b-R)return F elseif c=="\116\118"or c=="\116\097\114\103\101\116\118\101\108\111\099\105\116\121"then local F,c=targposvel(J,v,b-R)return c elseif c=="\100"or c=="\100\097\109\112\101\114"then return D elseif c=="\115"or c=="\115\112\101\101\100"then return W else error("\110\111 \118\097\108\117\101 "..(tostring(c).." \101\120\105\115\116\115"))end end function u.__newindex(F,c,b)local z=tick()if c=="\112"or c=="\112\111\115\105\116\105\111\110"then local F,c=posvel(D,W,e,V,J,v,z-R)local u,l=targposvel(J,v,z-R)e,V=b,c J,v=u,l elseif c=="\118"or c=="\118\101\108\111\099\105\116\121"then local F,c=posvel(D,W,e,V,J,v,z-R)local u,l=targposvel(J,v,z-R)e,V=F,b J,v=u,l elseif c=="\116\112"or c=="\116"or c=="\116\097\114\103\101\116\112\111\115\105\116\105\111\110"then local F,c=posvel(D,W,e,V,J,v,z-R)local u,l=targposvel(J,v,z-R)e,V=F,c J,v=b,l elseif c=="\116\118"or c=="\116\097\114\103\101\116\118\101\108\111\099\105\116\121"then local F,c=posvel(D,W,e,V,J,v,z-R)local u,l=targposvel(J,v,z-R)e,V=F,c J,v=u,b elseif c=="\100"or c=="\100\097\109\112\101\114"then local F,c=posvel(D,W,e,V,J,v,z-R)local u,l=targposvel(J,v,z-R)e,V=F,c J,v=u,l D=b elseif c=="\115"or c=="\115\112\101\101\100"then local F,c=posvel(D,W,e,V,J,v,z-R)local u,l=targposvel(J,v,z-R)e,V=F,c J,v=u,l W=b elseif c=="\097"or c=="\097\099\099\101\108\101\114\097\116\105\111\110"then R=tick()local F,c=posvel(D,W,e,V,J,v,z-R)local u,l=targposvel(J,v,z-R)e,V=F,c+b J,v=u,l else error("\110\111 \118\097\108\117\101 "..(tostring(c).." \101\120\105\115\116\115"))end R=z end return setmetatable(z,u)end return Spring
--[[
	Creates a new spring.
]]
function Spring.new(initial, td, ts)
	local d = td or 1
	local s = ts or 1
	local p0 = initial or 0
	local v0 = 0 * p0
	local p1 = p0
	local v1 = v0
	local t0 = tick()

	local selfmeta = {}
	local meta = {}

	function selfmeta.getpv()
		return posvel(d, s, p0, v0, p1, v1, tick() - t0)
	end

	function selfmeta.setpv(p, v)
		local time = tick()
		local tp, tv = targposvel(p1, v1, time - t0)
		p0, v0 = p, v
		p1, v1 = tp, tv
		t0 = time
	end

	function selfmeta.settargetpv(tp, tv)
		local time = tick()
		local p, v = posvel(d, s, p0, v0, p1, v1, time - t0)
		p0, v0 = p, v
		p1, v1 = tp, tv
		t0 = time
	end

	function selfmeta:accelerate(a)
		local time = tick()
		local p, v = posvel(d, s, p0, v0, p1, v1, time - t0)
		local tp, tv = targposvel(p1, v1, time - t0)
		p0, v0 = p, v + a
		p1, v1 = tp, tv
		t0 = time
	end

	function meta.__index(_self, index)
		local time = tick()
		if index == "p" or index == "position" then
			local p, _v = posvel(d, s, p0, v0, p1, v1, time - t0)
			return p
		elseif index == "v" or index == "velocity" then
			local _p, v = posvel(d, s, p0, v0, p1, v1, time - t0)
			return v
		elseif index == "tp" or index == "t" or index == "targetposition" then
			local tp, _tv = targposvel(p1, v1, time - t0)
			return tp
		elseif index == "tv" or index == "targetvelocity" then
			local _tp, tv = targposvel(p1, v1, time - t0)
			return tv
		elseif index == "d" or index == "damper" then
			return d
		elseif index == "s" or index == "speed" then
			return s
		else
			error("no value " .. tostring(index) .. " exists")
		end
	end

	function meta.__newindex(_self, index, value)
		local time = tick()
		if index == "p" or index == "position" then
			local _p, v = posvel(d, s, p0, v0, p1, v1, time - t0)
			local tp, tv = targposvel(p1, v1, time - t0)
			p0, v0 = value, v
			p1, v1 = tp, tv
		elseif index == "v" or index == "velocity" then
			local p, _v = posvel(d, s, p0, v0, p1, v1, time - t0)
			local tp, tv = targposvel(p1, v1, time - t0)
			p0, v0 = p, value
			p1, v1 = tp, tv
		elseif index == "tp" or index == "t" or index == "targetposition" then
			local p, v = posvel(d, s, p0, v0, p1, v1, time - t0)
			local _tp, tv = targposvel(p1, v1, time - t0)
			p0, v0 = p, v
			p1, v1 = value, tv
		elseif index == "tv" or index == "targetvelocity" then
			local p, v = posvel(d, s, p0, v0, p1, v1, time - t0)
			local tp, _tv = targposvel(p1, v1, time - t0)
			p0, v0 = p, v
			p1, v1 = tp, value
		elseif index == "d" or index == "damper" then
			local p, v = posvel(d, s, p0, v0, p1, v1, time - t0)
			local tp, tv = targposvel(p1, v1, time - t0)
			p0, v0 = p, v
			p1, v1 = tp, tv
			d = value
		elseif index == "s" or index == "speed" then
			local p, v = posvel(d, s, p0, v0, p1, v1, time - t0)
			local tp, tv = targposvel(p1, v1, time - t0)
			p0, v0 = p, v
			p1, v1 = tp, tv
			s = value
		elseif index == "a" or index == "acceleration" then
			t0 = tick()
			local p, v = posvel(d, s, p0, v0, p1, v1, time - t0)
			local tp, tv = targposvel(p1, v1, time - t0)
			p0, v0 = p, v + value
			p1, v1 = tp, tv
		else
			error("no value " .. tostring(index) .. " exists")
		end
		t0 = time
	end

	return setmetatable(selfmeta, meta)
end

return Spring
