Advertisement
rerere284

edge_distance

Apr 12th, 2016
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. --made by rerere284
  2. function init()
  3.     setName("Edge Distance")
  4.     setDesc("Gets how close things are to dark pixels")
  5.     setSize(100, 24+64+8+8+7+4)
  6.     addOutput(24+32)
  7.     addInput("Texture", 24+64+8+8)
  8. end
  9.  
  10. function apply()
  11.     tileSize = getTileSize()
  12.     for i=0, tileSize*tileSize-1 do
  13.         ax = i%tileSize
  14.         ay = math.floor(i/tileSize)
  15.         closest = 9999999
  16.         for j=0, tileSize*tileSize-1 do
  17.             bx = j%tileSize
  18.             by = math.floor(j/tileSize)
  19.             ar, ag, ab = getValue(0, bx, by, 100.0) --get pixel at that location
  20.             --if i ~= j then
  21.                 --dst = math.sqrt(((ax - bx)^2) + (ay - by)^2)/tileSize
  22.                 dst = (math.abs(ax - bx) + math.abs(ay - by))/(tileSize*2)
  23.                 brt = (ar + ag + ab)
  24.                 --brt = math.sqrt((ar^2) + (ag^2) + (ab^2))
  25.                 closeness = dst + (brt)
  26.                 if closeness < closest then
  27.                     closest = closeness
  28.                 end
  29.             --end
  30.         end
  31.         fr = closest
  32.         fg = closest
  33.         fb = closest
  34.         setPixel(0, ax, ay, fr, fg, fb)
  35.     end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement