-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find Midpoint Colours.lua
91 lines (72 loc) · 1.9 KB
/
Find Midpoint Colours.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
if not app.isUIAvailable then return end
local inputDialog = Dialog("Select Colours")
inputDialog:newrow {
always = true
}
inputDialog:color {
id = "colourOne",
label = "Colour 1"
}
inputDialog:color {
id = "colourTwo",
label = "Colour 2"
}
inputDialog:slider {
id = "midpoints",
label = "Midpoints",
min = 1,
max = 12,
value = 1
}
inputDialog:button {
id = "ok",
text = "OK",
onclick = function ()
inputDialog:close()
results = {
inputDialog.data.colourOne
}
local getMidValue = function (num1, num2, index)
return num1 + (index * ((num2 - num1) / (inputDialog.data.midpoints + 1)))
end
for i = 1, inputDialog.data.midpoints do
results[i+1] = Color {
red = getMidValue(inputDialog.data.colourOne.red, inputDialog.data.colourTwo.red, i),
green = getMidValue(inputDialog.data.colourOne.green, inputDialog.data.colourTwo.green, i),
blue = getMidValue(inputDialog.data.colourOne.blue, inputDialog.data.colourTwo.blue, i),
alpha = getMidValue(inputDialog.data.colourOne.alpha, inputDialog.data.colourTwo.alpha, i)
}
end
results [inputDialog.data.midpoints + 2] = inputDialog.data.colourTwo
local outputDialog = Dialog("Midpoint Colours")
outputDialog:newrow {
always = true
}
outputDialog:label {
text = "Left click to set as foreground colour."
}
outputDialog:label {
text = "Right click to add colour to palette."
}
outputDialog:shades {
mode = "pick",
colors = results,
onclick = function (event)
if event.button == MouseButton.LEFT then
-- set foreground colour
app.fgColor = event.color
elseif event.button == MouseButton.RIGHT then
if app.activeSprite == nil then -- check a sprite is open
app.alert ("Open a sprite first.")
else -- add colour to palette
app.command.AddColor {
color = event.color
}
end
end
end
}
outputDialog:show()
end
}
inputDialog:show()