-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpixelfunctions.lua
More file actions
executable file
·77 lines (68 loc) · 2.54 KB
/
pixelfunctions.lua
File metadata and controls
executable file
·77 lines (68 loc) · 2.54 KB
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
pixelFunction = {}
function pixelFunction.allwhite(x,y,r,g,b,a)
r, g, b, a = 255, 255, 255, 0
return r, g, b, a
end
function pixelFunction.clear(x,y,r,g,b,a)
r, g, b, a = 255, 255, 255, 0
return r, g, b, a
end
function pixelFunction.merge(x,y,r,g,b,a)
local nr, ng, nb, na = currentFrame[currentLayer]:getPixel(x, y)
if r == 0 and g == 0 and b == 0 and a == 0 then
else
r, g, b, a = nr, ng, nb, na
end
return r, g, b, a
end
function biggerPencil(x, y, size, color)
if not tmath.Within(x, y, currentData:getWidth(), currentData:getHeight()) then return end
if x == touchx + size then return end
if y == touchy + size then return end
currentData:setPixel(x, y, color)
x = x + 1
return biggerPencil(x, y, size, color)
end
function floodFill(x, y, target_color, replacement_color)
if not tmath.Within(x, y, currentData:getWidth(), currentData:getHeight()) then return
elseif target_color == replacement_color then return
elseif currentData:getPixel(x, y) ~= target_color then return
else
currentData:setPixel(x, y, replacement_color)
floodFill(x, y + 1, target_color, replacement_color)
floodFill(x, y - 1, target_color, replacement_color)
floodFill(x - 1, y, target_color, replacement_color)
floodFill(x + 1, y, target_color, replacement_color)
return floodFill(x, y, target_color, replacement_color)
end
end
function NewLayer()
table.insert(currentFrame, currentLayer + 1, love.image.newImageData(currentData:getWidth(), currentData:getHeight()))
currentLayer = currentLayer + 1
currentData = currentFrame[currentLayer]
LayerSpinner.max, LayerSpinner.value = #currentFrame, currentLayer
table.insert(FrameImages, currentLayer, love.graphics.newImage(currentFrame[currentLayer]))
currentimage = FrameImages[currentLayer]
end
function MoveLayer(direction)
local belowLayer = currentLayer + direction
currentFrame[currentLayer], currentFrame[belowLayer] = currentFrame[belowLayer], currentFrame[currentLayer]
FrameImages[currentLayer], FrameImages[belowLayer] = FrameImages[belowLayer], FrameImages[currentLayer]
LayerSpinner.value = LayerSpinner.value + direction
for i, v in pairs(FrameImages) do
v:refresh()
end
currentimage:refresh()
end
function RemoveLayer()
table.remove(currentFrame, currentLayer)
currentLayer = currentLayer - 1
currentData = currentFrame[currentLayer]
LayerSpinner.max, LayerSpinner.value = LayerSpinner.max - 1, currentLayer
table.remove(FrameImages, currentLayer + 1)
currentimage = FrameImages[currentLayer]
end
function MergeLayer()
currentFrame[currentLayer - 1]:mapPixel(pixelFunction.merge)
RemoveLayer()
end