Advertisement
Guest User

Zoom&Stretch

a guest
Oct 31st, 2019
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. function init()
  2.     setName("Zoom&Stretch")
  3.     setDesc("X and Y stretching")
  4.     setSize(120,18+18+24+64+8+8+7+4+18+18+18)
  5.     addOutput(24+32)
  6.     addInput("Texture",24+64+8+8)
  7.     addInputParameter("X pos","X position",18+24+64+8+8,0,0,64)
  8.     addInputParameter("Y pos","Y position",18+18+24+64+8+8,0,0,64)
  9.     addInputParameter("H fac","Horizontal stretching factor",18+18+18+24+64+8+8,1,1,64)
  10.     addInputParameter("V fac","Vertical stretching factor",18+18+18+18+24+64+8+8,1,1,64)
  11.     addInputParameter("Smooth","Smoothness",18+18+18+18+18+24+64+8+8,0,0,10)
  12. end
  13. -- Ugly way to use channels
  14. function apply()
  15.     x = 0
  16.     y = 0
  17.     tileSize = getTileSize()
  18.     for i=0, tileSize*tileSize-1 do
  19.         x = i%tileSize
  20.         y = math.floor(i/tileSize)
  21.         xnew = math.floor(x/getValue(3, 0, 0, 1)) + getValue(1, 0, 0, 1)
  22.         ynew = math.floor(y/getValue(4, 0, 0, 1)) + getValue(2, 0, 0, 1)
  23.         out = getValue(0, xnew, ynew, 1)
  24.         if (getValue(5, 0, 0, 1) > 0)then
  25.             for i=0, getValue(5, 0, 0, 1) do
  26.                 out = out+getValue(0, xnew+i, ynew+i, 1)
  27.                 out = out+getValue(0, xnew-i, ynew-i, 1)
  28.             end
  29.             out = out/(1+ 2*getValue(5, 0, 0, 1))
  30.         end
  31.        
  32.         setPixel(0,x,y,out,out,out)
  33.     end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement