Guest User

xycopyrect.lua

a guest
Dec 13th, 2020
91
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-CopyRect")
  4.   setDesc("Creates a repeating pattern")
  5.   setSize(100,108+124+16)
  6.   addOutput(24+32)
  7.   addInput("Texture", 24+64+8)
  8. -- 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
  9.   addParameter("Copy X", "Copy area X (left)", 108+16, 0, 0, 100, true)
  10.   addParameter("Copy Y", "Copy area Y (top)", 108+32, 0, 0, 100, true)
  11.   addParameter("Width", "Copy area (width)", 108+48, 50, 0, 100, true)
  12.   addParameter("Height", "Copy area (height)", 108+64, 50, 0, 100, true)
  13.   addParameter("Offset X", "Shift start of copied area", 108+80, 0, 0, 100, true)
  14.   addParameter("Offset Y", "Shift start of copied area", 108+96, 0, 0, 100, true)
  15.   addParameter("Stag X", "Stagger alternating rows of copied areas by X", 108+108, 0, 0, 100, true)
  16.   addParameter("Stag Y", "Stagger alternating columns of copied areas by Y", 108+124, 0, 0, 100, true)
  17. end
  18.  
  19. function apply()
  20.   size = getTileSize()
  21.   x = math.floor(getValue(1,0,0,1) / 100.0 * size)
  22.   y = math.floor(getValue(2,0,0,1) / 100.0 * size)
  23.   w = math.max(1,math.floor(getValue(3,0,0,1) / 100.0 * size))
  24.   h = math.max(1,math.floor(getValue(4,0,0,1) / 100.0 * size))
  25.   ofsx = math.floor(getValue(5,0,0,1) / 100.0 * size)
  26.   ofsy = math.floor(getValue(6,0,0,1) / 100.0 * size)
  27.   stagx = math.floor(getValue(7,0,0,1) / 100.0 * size)
  28.   stagy = math.floor(getValue(8,0,0,1) / 100.0 * size)
  29.   for dy = 0, size - 1 do
  30.    for dx = 0, size - 1 do
  31.     gx = (dx + ofsx) % w + x
  32.     gy = (dy + ofsy) % h + y
  33.     if stagx > 0 then
  34.         row = math.floor(dy / h)
  35.         if ( row % 2 == 1 ) then
  36.            gx = gx + stagx
  37.         end
  38.     end
  39.     if stagy > 0 then
  40.         col = math.floor(dx / w)
  41.         if ( col % 2 == 1 ) then
  42.           gy = gy + stagy
  43.         end
  44.     end
  45.     r,g,b=getValue(0,gx,gy,1)
  46.     setPixel(0,dx,dy, r,g,b)
  47.    end
  48.   end
  49. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×