jw_cad 外部変形 - (1272) 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

#!この次の行からプログラムを書いてください
hp = {}
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, "^hp[1-9]") then
    hp[string.gsub(string.gsub(F[1], "hp", ""), "-", "")*1] = {F[2], F[3]}
  end
end

d = math.rad(hk)
si = math.sin(d)
co = math.cos(d)
x1, y1 = hp[1][1], hp[1][2]
x2, y2 = hp[2][1], hp[2][2]
ww =   (x2 - x1) * co + (y2 - y1) * si
hh = - (x2 - x1) * si + (y2 - y1) * co
x3, y3 = x1 + ww * co, y1 + ww * si
x4, y4 = x1 - hh * si, y1 + hh * co
r, g, b = 0, 128, 128
print( ("lc10 %d"):format(r + 256 * g + 256 * 256 * b))
print( ("sl %s %s %s %s %s %s %s %s"):format(x1, y1, x3, y3, x2, y2, x4, y4))