Skip to content

Instantly share code, notes, and snippets.

@xpol
Created March 31, 2014 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpol/9886871 to your computer and use it in GitHub Desktop.
Save xpol/9886871 to your computer and use it in GitHub Desktop.
Create a series of image use to test TFT screen.
-- command line arg:
-- TFT.lua WxH
function check(arg)
if not arg[1] then
error('WxH arg not given!')
end
local w, h = arg[1]:match('(%d+)x(%d+)')
if not w or not h then
error('W or H not number!')
end
return tonumber(w), tonumber(h)
end
local function draw_line(cmd, x0, y0, x1, y1)
cmd[#cmd+1] = '-draw'
cmd[#cmd+1] = string.format("line %d,%d %d,%d", x0, y0, x1, y1)
end
local function draw_text(cmd, x, y, text)
local f = "text %d,%d '%s'"
cmd[#cmd+1] = '-draw'
cmd[#cmd+1] = f:format(x, y, text)
end
local function set_out_filename(cmd, filename)
cmd[#cmd+1] = filename
end
local function init_cmd(w, h)
return {'convert', '-size', w..'x'..h, 'xc:black', '-background', 'black', '-fill', 'white', '-font', 'Consolas'}
end
require('ex')
local function warp(i, N)
return i <= N and i or N-(i%N)
end
function make_cmd()
local W, H = check(arg)
local MAX = math.max(W, H)
local LEN = 20
for i=1,MAX do
local cmd = init_cmd(W, H)
if i <= W then draw_line(cmd, i-1, 0, i-1, H) end
if i <= H then draw_line(cmd, 0, i-1, W, i-1) end
draw_text(cmd, 8, H-8, string.format('%03d', i))
set_out_filename(cmd, string.format('%03d.jpg', i))
ex.spawn(cmd)
end
end
make_cmd()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment