Ningow

CustomScatter.Lua

Nov 3rd, 2020
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function init()
  2.     setName("Custom Scatter")
  3.     setDesc("Scatters texture")
  4.     setSize(100, 24+64+8+8+18*7+7+4)
  5.     addOutput(24+32)
  6.     addInput("Texture", 24+64+8+8)
  7.     addParameter("Seed", "RNG seed", 24+64+8+8+18, 0, -1, -1)
  8.     addParameter("Amount", "Amount", 24+64+8+8+18+18, 10, 0, 1000)
  9.     addParameter("Scale", "scale", 24+64+8+8+18+18+18, 50, 2, 100, true)
  10.     addParameter("Rand scale", "Random scale", 24+64+8+8+18+18+18+18, 50, 0, 99, true)
  11.     addParameter("Rotation", "Random rotation", 24+64+8+8+18+18+18+18+18, 100, 0, 100, true)
  12.     addParameter("Intensity", "Random intensity", 88+8*2+18*6, 100, 0, 100, true)
  13.     addParameter("Mode","Blend mode\n(0=max 1=add 2=overlay)",88+8*2+18*7,0,0,2)
  14. end
  15.  
  16. function apply()
  17.     tileSize = getTileSize()
  18.     posX= {}
  19.     posY= {}
  20.     intensity={}
  21.     scalex={}
  22.     scaley={}
  23.     rotation={}
  24.     amount = getValue(2,0,0,1)
  25.     scale = getValue(3,0,0,100)
  26.     randScale = getValue(4,0,0,100)
  27.     randRot = getValue(5,0,0,100)
  28.     randIntensity = getValue(6,0,0,100)
  29.     mode = getValue(7,0,0,1)
  30.     math.randomseed(getValue(1, 0, 0, 1))
  31.     for i=0, tileSize*tileSize-1 do--set all black
  32.         x = i%tileSize
  33.         y = math.floor(i/tileSize)
  34.         setPixel(0, x, y, 0, 0, 0)
  35.     end
  36.    
  37.     cols = {}
  38.     for i=0 , tileSize do
  39.         cols[i]={}
  40.         for j=0,tileSize do
  41.             cols[i][j]=0
  42.         end
  43.     end
  44.  
  45.     for i=0,amount-1 do--create values
  46.         posX[i]= math.floor(math.random()*tileSize)
  47.         posY[i]= math.floor(math.random()*tileSize)
  48.  
  49.         scalex[i] = scale*(1-randScale/2+math.random()*randScale)
  50.         scaley[i] = scale*(1-randScale/2+math.random()*randScale)
  51.  
  52.         intensity[i] = (1-math.random()*randIntensity)
  53.  
  54.         rotation[i] = math.pi *2* math.random()*randRot
  55.     end
  56.  
  57.     setPixel(0,0,0,1,1,0)
  58.     for i=0,amount-1 do--get pixel colors
  59.         multi = 2
  60.  
  61.         for x=0,math.floor(tileSize*scalex[i])*multi-1 do
  62.             for y=0,math.floor(tileSize*scaley[i])*multi-1 do
  63.                 ox=x/multi
  64.                 oy=y/multi
  65.  
  66.                 s = math.sin(rotation[i])
  67.                 c = math.cos(rotation[i])
  68.  
  69.                 x2=(x/multi*c-y/multi*s)
  70.                 y2=(x/multi*s+y/multi*c)
  71.  
  72.  
  73.                 x2=math.floor(x2+posX[i]+.5)%tileSize
  74.                 y2=math.floor(y2+posY[i]+.5)%tileSize
  75.                 value = 0
  76.                 value = getValue(0,ox/scalex[i],oy/scaley[i],0) *intensity[i]
  77.                 if mode==2 then
  78.                     for k=-1,1 do
  79.                         for l=-1,1 do
  80.                             value = value + getValue(0,ox/scalex[i]+k,oy/scaley[i]+l,0) *intensity[i] * (-math.pow(k,2)+2)* (-math.pow(l,2)+2)
  81.                     end
  82.                 end
  83.                     value = value / (4+4*2+4)
  84.                 end
  85.                
  86.  
  87.                 if mode==0 then
  88.                     value=math.max(value,cols[x2][y2])
  89.                 elseif mode==1 then
  90.                     value = value+cols[x2][y2]
  91.                 elseif mode==2 then
  92.                     value=math.max(value,cols[x2][y2])
  93.                 end
  94.                 cols[x2][y2] = value
  95.             end
  96.         end
  97.        
  98.         for x=0,tileSize-1 do--put on screen
  99.             for y=0,tileSize-1 do
  100.                 value=cols[x][y]
  101.                 setPixel(0,x,y,value,value,value)
  102.             end
  103.         end
  104.     end
  105. 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.

×