Advertisement
rerere284

Direction_to_Vector

Apr 14th, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. --made by rerere284
  2. function init()
  3.     setName("Direction to Vector")
  4.     setDesc("Converts Direction and Intensity to Vector X and Y.")
  5.     setSize(100, 24+64+64+8+8+18+7+4)
  6.     addOutput(24+32)
  7.     addOutput(24+64+32)
  8.     addInputParameter("Dir", "Direction.", 24+64+64+8+8,    1, -1, -1)
  9.     addInputParameter("Int", "Intensity.", 24+64+64+8+8+18, 0, -1, -1)
  10. end
  11.  
  12. function apply()
  13.     tileSize = getTileSize()
  14.    
  15.     for i=0, tileSize*tileSize-1 do
  16.         x = i%tileSize
  17.         y = math.floor(i/tileSize)
  18.         ar, ag, ab = getValue(0, x, y, 1) --get pixels at that location for both
  19.         br, bg, bb = getValue(1, x, y, 1)
  20.         a = (ar+ag+ab)/3
  21.         b = (br+bg+bb)/3
  22.         vx = math.sin(-a*(math.pi*2))*b
  23.         vy = math.cos(-a*(math.pi*2))*-b
  24.         setPixel(0, x, y, vx, vx, vx)
  25.         setPixel(1, x, y, vy, vy, vy)
  26.     end
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement