rerere284

gray_noise

Apr 12th, 2016
170
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --made by rerere284
  2. function init()
  3.     setName("Gray Noise")
  4.     setDesc("Generates gray noise")
  5.     setSize(100, 24+64+8+8+18+18+7+4)
  6.     addOutput(24+32)
  7.     addInputParameter("Number1", "First number", 24+64+8+8, 0, -1, -1)
  8.     addInputParameter("Number2", "Second number", 24+64+8+8+18, 0, -1, -1)
  9.     addParameter("Seed", "RNG seed", 24+64+8+8+18+18, 0, -1, -1)
  10. end
  11.  
  12. function lerp(a,b,t)
  13.     return ((1-t)*a) + (t*b)
  14. end
  15.  
  16. function apply()
  17.     tileSize = getTileSize()
  18.     math.randomseed(getValue(2, 0, 0, 1))
  19.     for i=0, tileSize*tileSize-1 do
  20.         x = i%tileSize
  21.         y = math.floor(i/tileSize)
  22.         ar, ag, ab = getValue(0, x, y, 100) --get pixels at that location for both
  23.         br, bg, bb = getValue(1, x, y, 100)
  24.         --return a random value between those two
  25.         tt = math.random(0,100)/100
  26.         fr = lerp(ar,br,tt)
  27.         fg = lerp(ag,bg,tt)
  28.         fb = lerp(ab,bb,tt)
  29.         setPixel(0, x, y, fr, fg, fb)
  30.         --setPixel(0, x, y, ar, bg, bb)
  31.     end
  32. end
RAW Paste Data