local c={}do c.__index=c function c.new(e,b)local W=setmetatable({},c)W.f=e W.p=b W.v=b*0 return W end function c.Update(b,c,e)local W=(b.f*2)*pi local i=b.p local Q=b.v local n=e-i local P=exp(-W*c)local u=e+(Q*c-n*(W*c+1))*P local s=((W*c)*(n*W-Q)+Q)*P b.p=u b.v=s return u end function c.Reset(e,c)e.p=c e.v=c*0 end end


local Spring = {} do
	Spring.__index = Spring

	function Spring.new(freq, pos)
		local self = setmetatable({}, Spring)
		self.f = freq
		self.p = pos
		self.v = pos*0
		return self
	end

	function Spring:Update(dt, goal)
		local f = self.f*2*pi
		local p0 = self.p
		local v0 = self.v

		local offset = goal - p0
		local decay = exp(-f*dt)

		local p1 = goal + (v0*dt - offset*(f*dt + 1))*decay
		local v1 = (f*dt*(offset*f - v0) + v0)*decay

		self.p = p1
		self.v = v1

		return p1
	end

	function Spring:Reset(pos)
		self.p = pos
		self.v = pos*0
	end
end
