-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscreentone.lua
348 lines (339 loc) · 7.13 KB
/
screentone.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
-- Ningow's Dither
function init()
setName("Screentone Dither")
setDesc("Dithering machine")
setSize(85,16+8+24+64+8+8+7+4)
addOutput(24+32)
addInput("",24+32)
addParameter("Intensity","Intensity",24+64+9,100,0,200,true)
addParameter("Style","Dithering style",16+24+64+9,1,0,7)
addParameter("Steps","Dithering steps",16+16+24+64+9,3,1,3)
end
-- Ugly way to use channels
function checker(x,y,sel)
if sel == 0 then
if (x+y)%2 == 0 then
return 0
end
return 1
elseif sel == 1 then
if (x+y)%4 == 0 or (x-y)%4 == 0 then
return 0
end
return 1
elseif sel == 2 then
if (x+y)%4 == 0 and x%2 == 0 and y%2 == 0 then
return 0
end
return 1
elseif sel == 3 then
if (x+y+1)%4 == 0 or (x-y+1)%4 == 0 then
return 1
end
return 0
elseif sel == 4 then
if (x+y)%4 == 0 and x%2 == 0 and y%2 ==0 then
return 1
end
return 0
end
end
function lined(x,y,sel)
if sel == 0 then
if y%2 == 0 then
return 0
end
return 1
elseif sel == 1 then
if y%2 == 0 and (x+y)%4 ~= 1 then
return 0
end
return 1
elseif sel == 2 then
if (y+1)%2 == 0 and (x+y+1)%4 ~= 1 then
return 1
end
return 0
end
end
function crossd(x,y,sel)
if sel == 0 then
if (x+y)%4 == 0 then
return 0
end
return 1
elseif sel == 1 then
if (x-y+1)%4 == 0 then
return 1
end
return 0
end
end
function block(x,y,sel,inv)
if sel == 0 then
if (x*y)%2 == 0 then
return 0+inv
end
return 1-inv
elseif sel == 1 then
if (x*y)%4 == 0 then
return 1-inv
end
return 0+inv
elseif sel == 2 then
if (x*y)%4 == 0 then
return 1-inv
end
return 0+inv
end
end
function fourline(x,y,sel,inv)
if sel == 0 then
if x%2 == 0 then
if x%4 == 0 and y%16 < 8 then
return 1-inv
else
return 0+inv
end
end
return 1-inv
elseif sel == 1 then
if x%4 == 0 and y%16 < 8 then
return 0+inv
end
return 1-inv
elseif sel == 2 then
if y%8 < 4 then
return 0+inv
end
return 1-inv
end
end
function apply()
math.randomseed (getValue(5,0,0,1))
x = 0
y = 0
tileSize = getTileSize()
intensity = getValue(1,0,0,100)
style = getValue(2,0,0,1)
steps = getValue(3,0,0,1)
for i=0, tileSize*tileSize-1 do
x = i%tileSize
y = math.floor(i/tileSize)
input = getValue(0,x,y,1)*intensity
if style == 0 then --No Dithering
if input > 0.5 then
out = 1
else
out = 0
end
elseif style == 1 then --Default Dither
if steps == 3 then
if input > 6/7 then out = 1
elseif input > 5/7 then
out = checker(x,y,2)
elseif input > 4/7 then
out = checker(x,y,1)
elseif input > 3/7 then
out = checker(x,y,0)
elseif input > 2/7 then
out = checker(x,y,3)
elseif input > 1/7 then
out = checker(x,y,4)
else out = 0
end
elseif steps == 2 then
if input > 4/5 then out = 1
elseif input > 3/5 then
out = checker(x,y,2)
elseif input > 2/5 then
out = checker(x,y,0)
elseif input > 1/5 then
out = checker(x,y+1,4)
else out = 0
end
else
if input > 2/3 then out = 1
elseif input > 1/3 then
out = checker(x,y,0)
else out = 0
end
end
elseif style == 2 then --H Lined
if steps == 3 then
if input > 6/7 then out = 1
elseif input > 5/7 then
out = checker(x+1,y,2)
elseif input > 4/7 then
out = lined(x,y,1)
elseif input > 3/7 then
out = lined(x,y,0)
elseif input > 2/7 then
out = lined(x,y,2)
elseif input > 1/7 then
out = checker(x+1,y+1,4)
else out = 0
end
elseif steps == 2 then
if input > 4/5 then out = 1
elseif input > 3/5 then
out = lined(x,y,1)
elseif input > 2/5 then
out = lined(x,y,0)
elseif input > 1/5 then
out = lined(x,y,2)
else out = 0
end
else
if input > 2/3 then out = 1
elseif input > 1/3 then
out = lined(x,y,0)
else out = 0
end
end
elseif style == 3 then --V Lined
if steps == 3 then
if input > 6/7 then out = 1
elseif input > 5/7 then
out = checker(y+1,x,2)
elseif input > 4/7 then
out = lined(y,x,1)
elseif input > 3/7 then
out = lined(y,x,0)
elseif input > 2/7 then
out = lined(y,x,2)
elseif input > 1/7 then
out = checker(y+1,x+1,4)
else out = 0
end
elseif steps == 2 then
if input > 4/5 then out = 1
elseif input > 3/5 then
out = checker(y+1,x,2)
elseif input > 2/5 then
out = lined(y,x,1)
elseif input > 1/5 then
out = checker(y+1,x+1,4)
else out = 0
end
else
if input > 2/3 then out = 1
elseif input > 1/3 then
out = lined(y,x,1)
else out = 0
end
end
elseif style == 4 then --Crossed
if steps == 3 then
if input > 6/7 then out = 1
elseif input > 5/7 then
out = checker(y,x,2)
elseif input > 4/7 then
out = crossd(y,x,0)
elseif input > 3/7 then
out = checker(y,x,1)
elseif input > 2/7 then
out = crossd(y,x,1)
elseif input > 1/7 then
out = checker(y+2,x+1,4)
else out = 0
end
elseif steps == 2 then
if input > 4/5 then out = 1
elseif input > 3/5 then
out = crossd(y,x,0)
elseif input > 2/5 then
out = checker(y,x,1)
elseif input > 1/5 then
out = crossd(y,x,1)
else out = 0
end
else
if input > 2/3 then out = 1
elseif input > 1/3 then
out = checker(y,x,1)
else out = 0
end
end
elseif style == 5 then --Blocks
if steps == 3 then
if input > 6/7 then out = 1
elseif input > 5/7 then
out = block(x,y,0,1)
elseif input > 4/7 then
out = block(x,y,1,0)
elseif input > 3/7 then
out = lined(y,x,0)
elseif input > 2/7 then
out = block(x,y,1,1)
elseif input > 1/7 then
out = block(x,y,0,0)
else out = 0
end
elseif steps == 2 then
if input > 4/5 then out = 1
elseif input > 3/5 then
out = block(x,y,0,1)
elseif input > 2/5 then
out = lined(y,x,0)
elseif input > 1/5 then
out = block(x,y,0,0)
else out = 0
end
else
if input > 2/3 then out = 1
elseif input > 1/3 then
out = block(x,y,0,0)
else out = 0
end
end
elseif style == 6 then --4x4 Vline
if steps == 3 then
if input > 6/7 then out = 1
elseif input > 5/7 then
out = fourline(x,y,1,0)
elseif input > 4/7 then
out = fourline(x,y,0,0)
elseif input > 3/7 then
out = lined(y,x,0)
elseif input > 2/7 then
out = fourline(x+1,y+8,0,1)
elseif input > 1/7 then
out = fourline(x+1,y+8,1,1)
else out = 0
end
elseif steps == 2 then
if input > 4/5 then out = 1
elseif input > 3/5 then
out = fourline(x,y,0,0)
elseif input > 2/5 then
out = lined(y,x,0)
elseif input > 1/5 then
out = fourline(x+1,y+8,0,1)
else out = 0
end
else
if input > 2/3 then out = 1
elseif input > 1/3 then
out = lined(y,x,0)
else out = 0
end
end
else --Random
if steps == 3 then
if input > (math.random(100,600)/700) then out = 1
else out = 0
end
elseif steps == 2 then
if input > (math.random(100,400)/500) then out = 1
else out = 0
end
else
if input > (math.random(100,200)/300) then out = 1
else out = 0
end
end
end
setPixel(0,x,y,out,out,out)
end
end