jw_cad 外部変形 - (1274) luaでソリッド図形の円環を描く -

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

 

luaでソリッド図形の円環を描く

:luaでソリッド図形の円環を描く
@echo off
set c=%*
if defined c call:set %c%
if exist %~dpn0.txt (
  for /f "tokens=*" %%a in (%~dpn0.txt) do call:set %%a
)
if not defined w set w=1
if not defined r2 set r2=0.5
if defined c (
  echo %w% %r2% > %~dpn0.txt
)

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 #c 扁平率(0.1~10.0) w, 内円半径比 r2/r =
REM #e

:set
if not defined w set w=%1
if not defined r2 set r2=%2
goto:eof

#!この次の行からプログラムを書いてください
hp = {}
w = os.getenv('w') or 1
r2 = os.getenv('r2') or 0.5
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)
x1, y1 = hp[1][1], hp[1][2]
x2, y2 = hp[2][1], hp[2][2]
r1 = math.sqrt( (x2 - x1) ^ 2 + (y2 - y1) ^ 2)
r, g, b = 0, 128, 128
print( ("lc10 %d"):format(r + 256 * g + 256 * 256 * b))
print( ("so %s %s %s %s %s %s %s %s"):format(x1, y1, r1, w, d, 0, 2 * math.pi, r1 * r2))