robbielyman / seamstress

seamstress is an art engine
GNU General Public License v3.0
123 stars 12 forks source link

proposal: non-linear `screen.level` #95

Closed p3r7 closed 9 months ago

p3r7 commented 10 months ago

@dndrks, thanks for adding the screen.level convenience!

this was something i was also defining to quickly adapt my norns scripts to seamstress.

however current implem scales the gradient linearly which is doesn't really translate to norns' current non-linear screen behavior.

if the aim of this function is to emulate norns' screen, i found that something like this feels more accurate:

--- sets greyscale color/brightness.
-- @tparam integer value (0-15; 0=off, 15=white)
-- @function screen.level
function screen.level(l)
  local g = util.explin(1, 16, 1, 255, l+1) - 1
  screen.color(g, g, g)
end

(NB: +1/-1 shenanigans to avoid dividing by 0)

this might mean adapting the value passed to the few screen.level calls in meadowphysics-seamstress/lib/screen.lua.

robbielyman commented 10 months ago

I’d accept a PR with this change, although maybe it would be good to precompute the results and do the function as a table lookup instead?

p3r7 commented 10 months ago

yes (for the precompute).

but i also just discovered that latest norns has a SYSTEM > DISPLAY > GAMMA config that when set to roughly 3 gives a more linear response...

which is a way better default! (pixel art drawn on other apps appear as they got drawn).

on norns, we're stuck w/ the "worse" default value of 1 (exponential, so more skewed towards the "bright" side of the spectrum) to not break the look of all the pre-existing scripts.

so come to think of it, i think it's be better to keep screen.level linear but eventually make another function for porting those older norns scripts (screen.level_exp?).