rerere284

regulate

Apr 12th, 2016
275
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --made by rerere284
  2. function init()
  3.     setName("Regulate")
  4.     setDesc("Modulo + Rounding")
  5.     setSize(100, 24+64+8+8+18+18+7+4)
  6.     addOutput(24+32)
  7.     addInput("Texture", 24+64+8+8)
  8.     addParameter("Modulo", "Loops over this value", 24+64+8+8+18, 10, 1, -1)
  9.     addParameter("Rounding", "Snaps to this value", 24+64+8+8+18+18, 1, 1, -1)
  10. end
  11.  
  12. function rnd(h)
  13.     if (h*100) % 1 > 0.5 then
  14.         return math.ceil(h*100)/100
  15.     else
  16.         return math.floor(h*100)/100
  17.     end
  18. end
  19.  
  20. function apply()
  21.     tileSize = getTileSize()
  22.     for i=0, tileSize*tileSize-1 do
  23.         x = i%tileSize
  24.         y = math.floor(i/tileSize)
  25.         mod = getValue(1, 0, 0, 1)/100
  26.         round = getValue(2, 0, 0, 1)/100
  27.         ar, ag, ab = getValue(0, x, y, 1) --get pixel at that location
  28.         fr = (rnd((ar % mod) * round)) / round
  29.         fg = (rnd((ag % mod) * round)) / round
  30.         fb = (rnd((ab % mod) * round)) / round
  31.         setPixel(0, x, y, fr, fg, fb)
  32.     end
  33. end
RAW Paste Data