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