外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。
luaで2重線を引く(2sen)
:luaで2重線を引く(2sen)
@echo off
set w=%1
for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
copy jwc_temp.txt myfiles > nul
more +%%n %0 | lua > jwc_temp.txt
)
goto:eof
REM #jww
REM #1-%d 始点を指示してください
REM #2%d 終点を指示してください
REM #k 線の幅| 200(L) | 400(R) | 120 | 150 | 180 | 220 | 250 | 300 | 350 |
REM #e
#!この次の行からプログラムを書いてください
function sprintf(...)
if #{...} == 0 then return end
if #{...} == 1 then return ... end
return string.format(...)
end
function printf(...)
return print(sprintf(...))
end
function join(a, FS)
if type(a) ~= "table" then return a end
if FS == nil then FS = " " end
return table.concat(flatten(a), FS)
end
function flatten(a)
local i, j, k
local c = {}
for i in pairs(a) do
if type(a[i]) == "table" then
--while #a[i] == 1 do a[i] = a[i][1] end
for j in pairs(a[i]) do
if type(a[i][j]) == "table" then
--while #a[i][j] == 1 do a[i][j] = a[i][j][1] end
for k in pairs(a[i][j]) do
table.insert(c, a[i][j][k])
end
else
table.insert(c, a[i][j])
end
end
else
table.insert(c, a[i])
end
end
return c
end
function ptslope(x, y)
local x1, y1 = x[1], x[2]
local x2, y2 = y[1], y[2]
return math.atan2(y2 - y1, x2 - x1)
end
function polar(r, d, w) --方向余弦のセット
if r == "" or r == nil then r = 1 end
if d == "" or d == nil then d = 0 end
if w == "" or w == nil then w = 1 end
return {r * math.cos(d), r * math.sin(d) * w}
end
function moveto(x, y) --点x を 相対距離 y [ a, b ] へ移動
return y and ptcalc("+", x, y) or x
end
function polarto(x, r, d, w) --点x を 極座標 [ r, d ] で相対的に移動する
return moveto(x, polar(r, d, w))
end
function ptcalc(p, x, y) --点データの数値演算(加減乗除)
local zz
zz = {x[1], x[2], y[1], y[2]}
if p == "+" then
return zz and {zz[1] + zz[3], zz[2] + zz[4]} or {0, 0}
elseif p == "-" then
return zz and {zz[1] - zz[3], zz[2] - zz[4]} or {0, 0}
elseif p == "*" then
return zz and {zz[1] * zz[3], zz[2] * zz[4]} or {0, 0}
elseif p == "/" then
return zz and {zz[1] / zz[3], zz[2] / zz[4]} or {0, 0}
elseif p == "ave" then
return zz and {(zz[1] + zz[3]) / 2, (zz[2] + zz[4]) / 2} or {0, 0}
else
return {0, 0}
end
end
function echo(...)
if #{...} == 0 then return end
return print(join({select(1, ...)}))
end
for line in io.lines("myfiles") do
F = {}
string.gsub(line, "%S+", function (x) table.insert(F, x) end)
if string.match(line, "^hp1") then p1 = {F[2], F[3]} end
if string.match(line, "^hp2") then p2 = {F[2], F[3]}
hw = {200, 400, 120, 150, 180, 220, 250, 300, 350}
r = hw[os.getenv('w')*1] / 2
d = ptslope(p1, p2) + math.rad(90)
echo(polarto(p1, r, d), polarto(p2, r, d))
if r then
echo(polarto(p1, -r, d), polarto(p2, -r, d))
p = math.deg(d)
echo("ci", p1, r, p, p + 180, 1, 0)
echo("ci", p2, r, p - 180, p, 1, 0)
end
end
end