]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_lamp/commitdiff
lampulator-love: experimental non-linear response curve
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 31 May 2020 21:53:39 +0000 (22:53 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 31 May 2020 21:53:39 +0000 (22:53 +0100)
linux-draw-love/draw.lua

index 8cee2dc0609c18980f86e120fc3d827ee8530ae2..bf01c6e0bda6ac57a4c9651218e0acb374330323 100644 (file)
@@ -81,17 +81,22 @@ function loaddrawfn(name)
   end
 end
 
+local function nonlinear(val)
+  if     val == 0    then return 0              -- 0 |-> 0
+  elseif val  < 0x10 then return 0x30 + val*13  -- [1, F] |-> [61, 243]
+  else                    return 0xFF           -- ... |-> 255
+  end
+end
+
 -- dump the ws2812 array into a LOVE image and push it into a channel
 function dodraw()
   local ix = 0, r, c
   for r = 0,3 do
     for c = 0,7 do
       ix = ix + 1 
-      imgd:setPixel(c, r,
-        math.min(0xFF,string.byte(remotefb[ix],2)*16)/256,
-        math.min(0xFF,string.byte(remotefb[ix],1)*16)/256,
-        math.min(0xFF,string.byte(remotefb[ix],3)*16)/256
-      )
+      imgd:setPixel(c, r, nonlinear(string.byte(remotefb[ix],2))/255,
+                          nonlinear(string.byte(remotefb[ix],1))/255,
+                          nonlinear(string.byte(remotefb[ix],3))/255)
     end
   end