mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
This commit is contained in:
parent
d8a627c58a
commit
3eb4eb3009
2 changed files with 10 additions and 6 deletions
|
|
@ -200,7 +200,7 @@ local function spring<T>(source: () -> T, period: number?, damping_ratio: number
|
||||||
return function()
|
return function()
|
||||||
track(output)
|
track(output)
|
||||||
return output.cache
|
return output.cache
|
||||||
end
|
end, data
|
||||||
end
|
end
|
||||||
|
|
||||||
local function step_springs(dt: number)
|
local function step_springs(dt: number)
|
||||||
|
|
@ -224,6 +224,9 @@ local function step_springs(dt: number)
|
||||||
local ff_123 = u_123*-c
|
local ff_123 = u_123*-c
|
||||||
local ff_456 = u_456*-c
|
local ff_456 = u_456*-c
|
||||||
|
|
||||||
|
|
||||||
|
--assert(math.abs(fs_123.X) >= (math.abs(ff_123.X)), "damping exceeds restoring")
|
||||||
|
|
||||||
-- calculate acceleration step
|
-- calculate acceleration step
|
||||||
local dv_123 = (fs_123 + ff_123)*dt
|
local dv_123 = (fs_123 + ff_123)*dt
|
||||||
local dv_456 = (fs_456 + ff_456)*dt
|
local dv_456 = (fs_456 + ff_456)*dt
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ local function main()
|
||||||
local effect = vide.effect
|
local effect = vide.effect
|
||||||
|
|
||||||
local value = source(MAX)
|
local value = source(MAX)
|
||||||
local sprung = spring(value, 1, 0.3)
|
local sprung, data = (spring :: any)(value, 1, 19.16)
|
||||||
|
|
||||||
effect(function()
|
effect(function()
|
||||||
local v = sprung()
|
local v = sprung()
|
||||||
|
|
@ -48,14 +48,15 @@ local function main()
|
||||||
local reset = "\27[H\27[2J" -- ANSI clear terminal
|
local reset = "\27[H\27[2J" -- ANSI clear terminal
|
||||||
local offset = string.rep("\n", MAX - fv + OFFSET)
|
local offset = string.rep("\n", MAX - fv + OFFSET)
|
||||||
local bar = testkit.color.gray(remainder_to_block(v - fv) .. "\n" .. string.rep(BLOCK .. "\n", fv))
|
local bar = testkit.color.gray(remainder_to_block(v - fv) .. "\n" .. string.rep(BLOCK .. "\n", fv))
|
||||||
print(reset .. offset .. bar)
|
local num = "\n" .. v
|
||||||
|
print(reset .. offset .. bar .. num)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local elapsed = 0
|
local T = 1.5
|
||||||
|
local elapsed = T/2
|
||||||
repeat local dt = step()
|
repeat local dt = step()
|
||||||
vide.step(dt)
|
vide.step(dt)
|
||||||
|
|
||||||
local T = 3
|
|
||||||
elapsed += dt
|
elapsed += dt
|
||||||
while elapsed >= T do
|
while elapsed >= T do
|
||||||
elapsed -= T
|
elapsed -= T
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue