Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fnl frame-based animator function in stdlib #450

Open
trentgill opened this issue Nov 15, 2021 · 0 comments
Open

fnl frame-based animator function in stdlib #450

trentgill opened this issue Nov 15, 2021 · 0 comments
Labels
feature new features yet to be added
Milestone

Comments

@trentgill
Copy link
Collaborator

from one of the Maps episodes, i made a function fnl that would 'funnel' a continuous change by turning it into discrete steps & calling a function at each point.

it is primarily focused at ii devices where you may want to step a parameter in a smooth way, but only have a discretely stepped function call available. thus the function could be ii.funnel or ii.fnl. special care should be paid to interaction with timeline.

it is somewhere between ASL and timeline, and i wonder if there is a way to unify it into the timeline module?

from here:

-- call a function repetitively in time
-- the arg to the function is interpolated fps times per second
-- dest_ms is a table of `to()` calls for ASL-like sequences
function fnl(fn, origin, dest_ms, fps)
    return clock.run(function()
        fps = fps or 15 -- default
        local spf = 1 / fps -- seconds per frame
        fn(origin)
        for _,v in ipairs(dest_ms) do
            local count = math.floor(v[3] * fps) -- number of iterations
            local stepsize = (v[2]-origin) / count -- how much to increment by each iteration
            while count > 0 do
                clock.sleep(spf)
                origin = origin + stepsize -- move toward destination
                count = count - 1 -- count iteration
                fn(origin)
            end
        end
    end)
end
@trentgill trentgill added the feature new features yet to be added label Nov 15, 2021
@trentgill trentgill added this to the v4.1 milestone Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new features yet to be added
Projects
None yet
Development

No branches or pull requests

1 participant