-
Notifications
You must be signed in to change notification settings - Fork 2
/
palette.lua
95 lines (77 loc) · 2.17 KB
/
palette.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
palette = {}
palette =
{
number = 3,
x = 176,
y = 6,
yColor = 6
}
palette.xColor = palette.x
for i = 1, palette.number do
palette["img"..i] = love.graphics.newImage("/images/palette"..i..".png")
end
palette.which = 1
palette.pressed = false
for i = 1, palette.number do
palette["iD"..i] = love.image.newImageData("/images/palette"..i..".png")
palette["img"..i]:setFilter("nearest", "nearest")
end
palette.img = function()
return palette["img"..palette.which]
end
palette.iD = function()
return palette["iD"..palette.which]
end
palette.scales = {
[1] = 8,
[2] = 32,
[3] = 32
}
palette.scale = function()
return palette.scales[palette.which]
end
palette.w = function()
return palette.img():getWidth() * palette.scale()
end
palette.h = function()
return palette.img():getHeight() * palette.scale()
end
palette.mouseInside = function()
return not (
love.mouse.getX() <= palette.x or
love.mouse.getY() <= palette.y or
love.mouse.getX() >= palette.x + palette.w() or
love.mouse.getY() >= palette.y + palette.h()
)
end
palette.getColor = function(theX, theY)
local x, y = love.mouse.getX(), love.mouse.getY()
if theX and theY then
x, y = theX, theY
end
local rx = math.floor((x - palette.x) / palette.scale())
local ry = math.floor((y - palette.y) / palette.scale())
--print(rx, ry)
local r, g, b, a = palette.iD():getPixel(rx, ry)
local c = {r, g, b, a}
--print(r, g, b, a)
return c
end
palette.change = function(index)
palette.which = palette.which + 1
if index then palette.which = index end
if palette.which > palette.number then
palette.which = 1
end
palette.changeSquare(palette.xColor, palette.yColor)
end
palette.changeSquare = function(x, y)
palette.xColor = palette.x + math.floor((x - palette.x) / palette.scale()) * palette.scale()
palette.yColor = palette.y + math.floor((y - palette.y) / palette.scale()) * palette.scale()
end
palette.getSquare = function(x, y, scale)
local x = palette.x + math.floor((x - palette.x) / scale) * scale
local y = palette.y + math.floor((y - palette.y) / scale) * scale
return x, y, scale, scale
end
palette.__index = palette