rerere284

Vector_to_Direction

Apr 14th, 2016
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --made by rerere284
  2. function init()
  3.     setName("Vector to Direction")
  4.     setDesc("Converts vector x and y to direction and intensity.")
  5.     setSize(100, 24+64+64+8+8+18+7+4)
  6.     addOutput(24+32)
  7.     addOutput(24+64+32)
  8.     addInputParameter("X", "X value of vector.", 24+64+64+8+8,    1, -1, -1)
  9.     addInputParameter("Y", "Y value of vector.", 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.         dir = math.atan2(-a,-b)/(math.pi*2)
  23.         str = math.sqrt((a*a)+(b*b))
  24.         setPixel(0, x, y, dir, dir, dir)
  25.         setPixel(1, x, y, str, str, str)
  26.     end
  27. end
RAW Paste Data