# xycutoff.lua

a guest
Dec 13th, 2020
36
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. -- lostastronaut.com submits free node for Tilemancer
2. function init()
3.   setName("XY-Cutoff")
4.   setDesc("Trims")
5.   setSize(100,108+96)
9. -- note, if you change the size of the tile globally, you must delete and replace this node since i'm not sure how to update parameter max values
10.   addParameter("X", "The amount of pixels to cutoff by in the X axis", 108+16, 0, 0, getTileSize())
11.   addParameter("Y", "The amount of pixels to cutoff by in the Y axis", 108+32, 0, 0, getTileSize())
12.   addParameter("X Mode", "X Cutoff Mode\n0 - Greater\n1 - Less\n2 - Equals\n3 - Greater Equal\n4 - Lesser Equal", 108+48, 3, 0, 4)
13.   addParameter("Y Mode", "Y Cutoff Mode\n0 - Greater\n1 - Less\n2 - Equals\n3 - Greater Equal\n4 - Lesser Equal", 108+64, 3, 0, 4)
14.   addParameter("XY Mode", "XY Cutoff Mode\n0 - x AND y\n1 - x OR y\n2 - x XOR y\n3 - NOT (x AND y)\n4 - NOT (x OR y)\n5 - NOT (x XOR y)", 108+64+16, 0, 0, 5 )
15. end
16.
17. function apply()
18.   size = getTileSize()
19.   xCutoff = getValue(2, 0, 0, 1)
20.   yCutoff = getValue(3, 0, 0, 1)
21.   xmode = getValue(4,0,0,1)
22.   ymode = getValue(5,0,0,1)
23.   xymode = getValue(6,0,0,1)
24.   for i = 0, size * size - 1 do
25.     x = i%size
26.     y = math.floor(i/size)
27.     ar, ag, ab = getValue(0, x, y, 1)
28.     br, bg, bb = getValue(1, x, y, 1)
29.     xCut = (xmode==0 and x > xCutoff) or (xmode==1 and x < xCutoff) or (xmode==2 and x==xCutoff) or (xmode==3 and x>=xCutoff) or (xmode==4 and x<=xCutoff)
30.     yCut = (ymode==0 and y > yCutoff) or (ymode==1 and y < yCutoff) or (ymode==2 and y==yCutoff) or (ymode==3 and y>=yCutoff) or (ymode==4 and y<=yCutoff)
31.     a=true
32.     if xymode==0 then
33.      a = ( xCut and yCut )
34.     elseif xymode==1 then
35.      a = ( xCut or yCut )
36.     elseif xymode==2 then
37.      a = ( xCut ~ yCut )
38.     elseif xymode==3 then
39.      a = not (xCut and yCut )
40.     elseif xymode==4 then
41.      a = not ( xCut or yCut )
42.     elseif xymode==5 then
43.      a = not ( xCut ~ yCut )
44.     end
45.     if ( a ) then
46.         setPixel(0,x,y,ar,ag,ab)
47.     else
48.         setPixel(0,x,y,br,bg,bb)
49.     end
50.   end
51. end
RAW Paste Data