Last active
November 15, 2023 01:29
-
-
Save trentgill/709b3bb60ba1d48fb1f4e84045ed85e9 to your computer and use it in GitHub Desktop.
timeline chance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- some possible implementations of a probable function | |
-- really comes down to whether it's a timeline native behaviour | |
-- or if we just want a general fn to a wrap an application with chance | |
-- original version without chance | |
notesss = { 1, kick | |
, 1, {ii.wsyn.play_note, s{0,-12}, 2} | |
} | |
-- tl.chance is a function that takes a probability, and an action | |
-- note: the action can be an 'action table' in the timeline sense, to be applied at runtime | |
notesss = { 1, tl.chance(0.5, kick) | |
, 1, tl.chance(0.6, {ii.wsyn.play_note, s{0,-12}, 2}) | |
} | |
-- some as tl.chance, but instead it's a *global* function for probablistically calling it's 2nd arg | |
-- nb: requires handling of table-actions, which is perhaps timeline specific? | |
notesss = { 1, chance(0.5, kick) | |
, 1, chance(0.6, {ii.wsyn.play_note, s{0,-12}, 2}) | |
} | |
-- same again, but here we don't allow chance to have an action table | |
-- instead it just returns a fn that might execute it's inner-section | |
-- nb: any sequins will always advance, even if chance doesn't succeed | |
notesss = { 1, chance(0.5, kick) | |
, 1, {chance(0.6, ii.wsyn.play_note), s{0,-12}, 2}) | |
} | |
-- here we support it directly in timeline as a probability string | |
-- we already have a similar technique for "reset" | |
-- this gets weird because the action-table starts to get quite long | |
-- ? should the following action be sub-tabled, or is this clear enough? | |
-- strings are annoying bc math is hard, but numbers (0.5) are not clear as to what their purpose is | |
notesss = { 1, {'50%', kick} | |
, 1, {'60%', ii.wsyn.play_note, s{0,-12}, 2} | |
} | |
-- this is a simple version of timeline.apply | |
-- this does *not* support realizing sequins values within the action-table | |
function apply(fn, ...) | |
if type(fn) == 'table' then | |
return apply(table.unpack(fn)) -- unpack & recur | |
else return fn(...) end | |
end | |
function chance(prob, ...) | |
return function() | |
if math.random() <= prob then | |
return apply(...) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment