Advertisement
Guest User

MirrMix

a guest
Oct 31st, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.86 KB | None | 0 0
  1. function init()
  2.     setName("MirrMix")
  3.     setDesc("Mix with the mirror image")
  4.     setSize(95,18+24+32+24+64+8+8+7+4+18+18)
  5.     addOutput(24+32)
  6.     addInput("Texture",24+64+8+8,0,0,1)
  7.     addInputParameter("Loop H","Loop Horizontally",18+18+24+64+8+8,0,0,1)
  8.     addInputParameter("Loop V","Loop Vertically",18+18+24+64+8+8+18,0,0,1)
  9.     addParameter("Mix","Mix looped image",18+18+18+18+24+64+8+8,100,0,100, true)
  10.     addParameter("MixType","0:Clip 1:Opacity 2:Textured clip 3:Textured Opacity",18+18+18+18+24+64+8+8+18,0,0,3)
  11.     addParameter("MirrorType","0:Average 1:Darken 2:Lighten",18+18+18+18+24+64+8+8+18+18,0,0,2)
  12.     addInput("Mix",18+24+64+8+8,0,0,1)
  13. end
  14. -- Ugly way to use channels
  15. function loopr(x, y, ori)
  16.     xy = getValue(0,x,y,1)--image not mirrowed
  17.     mx = getValue(0,size-x,y,1)--image mirrowed in x
  18.     my = getValue(0,x,size-y,1)--image mirrowed in y
  19.     mxy = getValue(0,size-x,size-y,1)--image mirrowed in x and y
  20.    
  21.     if(getValue(5,0,0,1) == 0) then
  22.    
  23.         if (ori==0) then --H
  24.             return (xy + mx)/2
  25.         end
  26.         if (ori==1) then --v
  27.             return (xy + my)/2
  28.         end
  29.         if (ori==2) then --HV
  30.             return (xy + mx + my + mxy)/4
  31.         end
  32.     end
  33.     if(getValue(5,0,0,1) == 1) then
  34.    
  35.         if (ori==0) then --H
  36.             return math.min(xy , mx)
  37.         end
  38.         if (ori==1) then --v
  39.             return math.min(xy , my)
  40.         end
  41.         if (ori==2) then --HV
  42.             return math.min(xy , mx, my, mxy)
  43.         end
  44.     end
  45.     if(getValue(5,0,0,1) == 2) then
  46.    
  47.         if (ori==0) then --H
  48.             return math.max(xy , mx)
  49.         end
  50.         if (ori==1) then --v
  51.             return math.max(xy , my)
  52.         end
  53.         if (ori==2) then --HV
  54.             return math.max(xy , mx, my, mxy)
  55.         end
  56.     end
  57. end
  58.    
  59. function apply()
  60.     tileSize = getTileSize()
  61.     if (getValue(4,0,0,1) == 0) then --clip loop
  62.         for i=0, tileSize*tileSize-1 do
  63.             x = i%tileSize --get x
  64.             y = math.floor(i/tileSize) --get y
  65.             size = tileSize-1
  66.             valuexy = getValue(0,x,y,1)--normal image
  67.             loopperc = getValue(3,x,y,50)
  68.             if (getValue(1,0,0,1) == 1 and getValue(2,0,0,1) == 0) then --if H and not V
  69.                 opacityIndex = math.max(0, math.min(1, math.abs( ((size/2) - x )/(size/2) )+(loopperc-1) ))--middle H gradient
  70.                 looped = loopr(x,y,0)
  71.                 if (opacityIndex>0.5) then--boolMask
  72.                     setPixel(0,x,y,looped,looped,looped)
  73.                 else
  74.                     setPixel(0,x,y,valuexy,valuexy,valuexy)
  75.                 end
  76.             end
  77.             if (getValue(1,0,0,1) == 0 and getValue(2,0,0,1) == 1) then --if V and not H
  78.                 opacityIndex = math.max(0, math.min(1, math.abs( ((size/2) - y )/(size/2) )+(loopperc-1) ))--middle V gradient
  79.                 looped = loopr(x,y,1)
  80.                 if (opacityIndex>0.5) then--boolMask
  81.                     setPixel(0,x,y,looped,looped,looped)
  82.                 else
  83.                     setPixel(0,x,y,valuexy,valuexy,valuexy)
  84.                 end
  85.             end
  86.             if (getValue(1,0,0,1) == 1 and getValue(2,0,0,1) == 1) then --if H and V
  87.                 opacityIndex = math.max(0, math.min(1, math.max( math.abs( ((size/2) - x )/(size/2) )+(loopperc-1), math.abs( ((size/2) - y )/(size/2) )+(loopperc-1) )))--middle sqr gradient
  88.                 looped = loopr(x,y,2)
  89.                 if (opacityIndex>0.5) then--boolMask
  90.                     setPixel(0,x,y,looped,looped,looped)
  91.                 else
  92.                     setPixel(0,x,y,valuexy,valuexy,valuexy)
  93.                 end
  94.             end
  95.             if (getValue(1,0,0,1) == 0 and getValue(2,0,0,1) == 0) then --if neithe
  96.                 setPixel(0,x,y,valuexy,valuexy,valuexy)
  97.             end
  98.             --setPixel(0,x,y,opacityIndex,opacityIndex,opacityIndex)
  99.         end
  100.     end
  101.  
  102.     if (getValue(4,0,0,1) == 1) then --opacity loop
  103.         for i=0, tileSize*tileSize-1 do
  104.             x = i%tileSize --get x
  105.             y = math.floor(i/tileSize) --get y
  106.             size = tileSize-1
  107.             valuexy = getValue(0,x,y,1)--normal image
  108.             loopperc = getValue(3,x,y,50)
  109.             if (getValue(1,0,0,1) == 1 and getValue(2,0,0,1) == 0) then --if H and not V
  110.                 opacityIndex = math.max(0, math.min(1, math.abs( ((size/2) - x )/(size/2) )+(loopperc-1) ))--middle H gradient
  111.                 looped = loopr(x,y,0)
  112.                 mixImage = (looped * opacityIndex)+(valuexy * (1-opacityIndex))--mixes img and loopd img
  113.                 setPixel(0,x,y,mixImage,mixImage,mixImage)
  114.             end
  115.             if (getValue(1,0,0,1) == 0 and getValue(2,0,0,1) == 1) then --if V and not H
  116.                 opacityIndex = math.max(0, math.min(1, math.abs( ((size/2) - y )/(size/2) )+(loopperc-1) ))--middle V gradient
  117.                 looped = loopr(x,y,1)
  118.                 mixImage = (looped * opacityIndex)+(valuexy * (1-opacityIndex))--mixes img and loopd img
  119.                 setPixel(0,x,y,mixImage,mixImage,mixImage)
  120.             end
  121.             if (getValue(1,0,0,1) == 1 and getValue(2,0,0,1) == 1) then --if H and V
  122.                 opacityIndex = math.max(0, math.min(1, math.max( math.abs( ((size/2) - x )/(size/2) )+(loopperc-1), math.abs( ((size/2) - y )/(size/2) )+(loopperc-1) )))--middle sqr gradient
  123.                 looped = loopr(x,y,2)
  124.                 mixImage = (looped * opacityIndex)+(valuexy * (1-opacityIndex))--mixes img and loopd img
  125.                 setPixel(0,x,y,mixImage,mixImage,mixImage)
  126.             end
  127.             if (getValue(1,0,0,1) == 0 and getValue(2,0,0,1) == 0) then --if neithe
  128.                 setPixel(0,x,y,valuexy,valuexy,valuexy)
  129.             end
  130.             --setPixel(0,x,y,opacityIndex,opacityIndex,opacityIndex)
  131.         end
  132.     end
  133.  
  134.     if (getValue(4,0,0,1) == 2) then --textured clip
  135.         for i=0, tileSize*tileSize-1 do
  136.             x = i%tileSize --get x
  137.             y = math.floor(i/tileSize) --get y
  138.             size = tileSize-1
  139.             valuexy = getValue(0,x,y,1)--normal image
  140.             loopperc = getValue(3,x,y,50)
  141.             if (getValue(1,0,0,1) == 1 and getValue(2,0,0,1) == 0) then --if H and not V
  142.                 opacityIndex = math.max(0, math.min(1, getValue(6,x,y,1)+ (loopperc-1) ))--middle H gradient
  143.                 looped = loopr(x,y,0)
  144.                 if (opacityIndex>0.5) then--boolMask
  145.                     setPixel(0,x,y,looped,looped,looped)
  146.                 else
  147.                     setPixel(0,x,y,valuexy,valuexy,valuexy)
  148.                 end
  149.             end
  150.             if (getValue(1,0,0,1) == 0 and getValue(2,0,0,1) == 1) then --if V and not H
  151.                 opacityIndex = math.max(0, math.min(1, getValue(6,x,y,1)+ (loopperc-1) ))--middle H gradient
  152.                 looped = loopr(x,y,1)
  153.                 if (opacityIndex>0.5) then--boolMask
  154.                     setPixel(0,x,y,looped,looped,looped)
  155.                 else
  156.                     setPixel(0,x,y,valuexy,valuexy,valuexy)
  157.                 end
  158.             end
  159.             if (getValue(1,0,0,1) == 1 and getValue(2,0,0,1) == 1) then --if H and V
  160.                 opacityIndex = math.max(0, math.min(1, getValue(6,x,y,1)+ (loopperc-1) ))--middle H gradient
  161.                 looped = loopr(x,y,2)
  162.                 if (opacityIndex>0.5) then--boolMask
  163.                     setPixel(0,x,y,looped,looped,looped)
  164.                 else
  165.                     setPixel(0,x,y,valuexy,valuexy,valuexy)
  166.                 end
  167.             end
  168.             if (getValue(1,0,0,1) == 0 and getValue(2,0,0,1) == 0) then --if neithe
  169.                 setPixel(0,x,y,valuexy,valuexy,valuexy)
  170.             end
  171.             --setPixel(0,x,y,opacityIndex,opacityIndex,opacityIndex)
  172.         end
  173.     end
  174.  
  175.     if (getValue(4,0,0,1) == 3) then --textured opacity
  176.         for i=0, tileSize*tileSize-1 do
  177.             x = i%tileSize --get x
  178.             y = math.floor(i/tileSize) --get y
  179.             size = tileSize-1
  180.             valuexy = getValue(0,x,y,1)--normal image
  181.             loopperc = getValue(3,x,y,50)
  182.             if (getValue(1,0,0,1) == 1 and getValue(2,0,0,1) == 0) then --if H and not V
  183.                 opacityIndex = math.max(0, math.min(1, getValue(6,x,y,1)+ (loopperc-1) ))--middle H gradient
  184.                 looped = loopr(x,y,0)
  185.                 mixImage = (looped * opacityIndex)+(valuexy * (1-opacityIndex))--mixes img and loopd img
  186.                 setPixel(0,x,y,mixImage,mixImage,mixImage)
  187.             end
  188.             if (getValue(1,0,0,1) == 0 and getValue(2,0,0,1) == 1) then --if V and not H
  189.                 opacityIndex = math.max(0, math.min(1, getValue(6,x,y,1)+ (loopperc-1) ))--middle H gradient
  190.                 looped = loopr(x,y,1)
  191.                 mixImage = (looped * opacityIndex)+(valuexy * (1-opacityIndex))--mixes img and loopd img
  192.                 setPixel(0,x,y,mixImage,mixImage,mixImage)
  193.             end
  194.             if (getValue(1,0,0,1) == 1 and getValue(2,0,0,1) == 1) then --if H and V
  195.                 opacityIndex = math.max(0, math.min(1, getValue(6,x,y,1)+ (loopperc-1) ))--middle H gradient
  196.                 looped = loopr(x,y,2)
  197.                 mixImage = (looped * opacityIndex)+(valuexy * (1-opacityIndex))--mixes img and loopd img
  198.                 setPixel(0,x,y,mixImage,mixImage,mixImage)
  199.             end
  200.             if (getValue(1,0,0,1) == 0 and getValue(2,0,0,1) == 0) then --if neithe
  201.                 setPixel(0,x,y,valuexy,valuexy,valuexy)
  202.             end
  203.             --setPixel(0,x,y,opacityIndex,opacityIndex,opacityIndex)
  204.         end
  205.     end
  206.  
  207.  
  208. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement