aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2023-09-17 15:34:31 -0400
committerAdam Harrison <adamdharrison@gmail.com>2023-09-17 15:35:55 -0400
commit5f7a391fd1efff6fad4bc507acc38e82c90276b6 (patch)
tree7fb3f26c13f47ea0fb3c5de77e7aa2883478dfc3 /scripts
parent5bc91eaa6dc45019a98dc27b98923e446b767c28 (diff)
downloadlite-xl-colors-5f7a391fd1efff6fad4bc507acc38e82c90276b6.tar.gz
lite-xl-colors-5f7a391fd1efff6fad4bc507acc38e82c90276b6.zip
Added in auto-generation and ran for the first time.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/make_preview_image.lua79
1 files changed, 39 insertions, 40 deletions
diff --git a/scripts/make_preview_image.lua b/scripts/make_preview_image.lua
index 6bcaac8..d1d48be 100755
--- a/scripts/make_preview_image.lua
+++ b/scripts/make_preview_image.lua
@@ -1,51 +1,50 @@
#!/usr/bin/lua
-local filename = ...
-local name = filename:match("([^\\/]+)%..*$")
-
-
--- get colors
-local text = io.open(filename):read("*a")
-local colors = {}
-for r, g, b in text:gmatch("#(%x%x)(%x%x)(%x%x)") do
- r = tonumber(r, 16)
- g = tonumber(g, 16)
- b = tonumber(b, 16)
- table.insert(colors, { r, g, b })
-end
+for i, filename in ipairs({ ... }) do
+ local name = filename:match("([^\\/]+)%..*$")
+
+ -- get colors
+ local text = io.open(filename):read("*a")
+ local colors = {}
+ for r, g, b in text:gmatch("#(%x%x)(%x%x)(%x%x)") do
+ r = tonumber(r, 16)
+ g = tonumber(g, 16)
+ b = tonumber(b, 16)
+ table.insert(colors, { r, g, b })
+ end
-table.sort(colors, function(a, b)
- return a[1] + a[2] + a[3] < b[1] + b[2] + b[3]
-end)
+ table.sort(colors, function(a, b)
+ return a[1] + a[2] + a[3] < b[1] + b[2] + b[3]
+ end)
-local function eq(a, b)
- return a[1] == b[1] and a[2] == b[2] and a[3] == b[3]
-end
-
-local prev = {}
-for i = #colors, 1, -1 do
- if eq(colors[i], prev) then
- table.remove(colors, i)
- else
- prev = colors[i]
+ local function eq(a, b)
+ return a[1] == b[1] and a[2] == b[2] and a[3] == b[3]
end
-end
+ local prev = {}
+ for i = #colors, 1, -1 do
+ if eq(colors[i], prev) then
+ table.remove(colors, i)
+ else
+ prev = colors[i]
+ end
+ end
---generate svg file
-local w = 200
-local h = 16
-local fp = io.open("previews/" .. name .. ".svg", "wb")
-fp:write('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'..w..'" height="'..h..'" shape-rendering="crispEdges"> \n')
+ --generate svg file
+ local w = 200
+ local h = 16
+ local fp = io.open("previews/" .. name .. ".svg", "wb")
-for i = 1, #colors do
- local width = w/#colors
- local r, g, b = table.unpack(colors[i])
- local rect = '<rect x="'..(i-1)*width..'" width="'..width..'" height="'..h..'" fill="rgb('..r..', '..g..', '..b..')"></rect> \n'
- fp:write(rect)
-end
+ fp:write('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'..w..'" height="'..h..'" shape-rendering="crispEdges"> \n')
-fp:write('</svg>')
-fp:close()
+ for i = 1, #colors do
+ local width = w/#colors
+ local r, g, b = table.unpack(colors[i])
+ local rect = '<rect x="'..(i-1)*width..'" width="'..width..'" height="'..h..'" fill="rgb('..r..', '..g..', '..b..')"></rect> \n'
+ fp:write(rect)
+ end
+ fp:write('</svg>')
+ fp:close()
+end