Advertisement
Guest User

CrossCut

a guest
May 9th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. function init()
  2.     setName("CrossCut")
  3.     setDesc("Bend texture into a shape")
  4.     setSize(100, 4+18+18+24+64+8+8+18+18+7+4)
  5.     addOutput(24+32)
  6.     addOutput(64+24+32)
  7.     addInput("", 24+32)
  8.     addInputParameter("Direction", "0:horizontal 1:vertical", 64+24+64+8, 0, 0, 1)
  9.     addInputParameter("Position", "Position cut", 64+24+64+8+18, 0, 0, getTileSize())
  10. end
  11.  
  12. function normalize(x, y, z)
  13.     l = math.sqrt(x*x+y*y+z*z)
  14.     return x/l, y/l, z/l
  15. end
  16.  
  17. function apply()
  18.     tileSize = getTileSize()
  19.     for i=0, tileSize*tileSize-1 do
  20.         x = i%tileSize
  21.         y = math.floor(i/tileSize)
  22.         t = getValue(2,x,y,1)
  23.         if (getValue(1,0,0,1) == 0) then
  24.             outr,outg,outb = getValue(0,x,y,0)
  25.             if (y == t) then
  26.                 outr,outg,outb = 1-getValue(0,x,y,0)
  27.             end
  28.             setPixel(0, x, y, outr, outg, outb)
  29.             outr,outg,outb = getValue(0,x,t,0)
  30.         end
  31.         if (getValue(1,0,0,1) == 1) then
  32.             outr,outg,outb = getValue(0,x,y,0)
  33.             if (x == t) then
  34.                 outr,outg,outb = 1-getValue(0,x,y,0)
  35.             end
  36.             setPixel(0, x, y, outr, outg, outb)
  37.             outr,outg,outb = getValue(0,t,y,0)
  38.         end
  39.         setPixel(1, x, y, outr, outg, outb)
  40.     end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement