jw_cad 外部変形 - (517) luaで矩形を描く -

外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。

 

luaで矩形を描く

:luaで矩形を描く
@echo off
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 #e

#!この次の行からプログラムを書いてください
FS = " "
for line in io.lines("myfiles") do
  F = {}
  string.gsub(line, "%S+", function (x) table.insert(F, x) end)
  if string.match(line, "^hk") then hk = F[2] end
  if string.match(line, "^hp1") then x1, y1 = F[2], F[3] end
  if string.match(line, "^hp2") then x2, y2 = F[2], F[3] end
end
d  = math.rad(hk)
co = math.cos(d)
si = math.sin(d)
ww = (x2 - x1) * co + (y2 - y1) * si
hh =-(x2 - x1) * si + (y2 - y1) * co
p3 = x1 + ww * co .. FS .. y1 + ww * si
p4 = x1 - hh * si .. FS .. y1 + hh * co
print(x1 .. FS .. y1)
print(p3)
print(x2 .. FS .. y2)
print(p4)
print(x1 .. FS .. y1)