jw_cad 外部変形 - (793) rubyでソリッド図形の円を描く -

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

 

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

:rubyでソリッド図形の円を描く
@echo off
call %~dp0set "w" "%1" %~dpn0.txt
ruby -x %0 jwc_temp.txt
goto:eof

REM #jww
REM #1-%d 中心点を指示してください
REM #2%d 円周上の点を指示してください
REM #c 扁平率(0.1~10.0) w =
REM #e

#!ruby -Ks -an -i.bak
BEGIN { include Math }
case $_
  when /^hk/ then hk = $F[1].to_f
  when /^hp1/ then p1 = $F[1, 2].map { |x| x.to_f }
  when /^hp2/ then p2 = $F[1, 2].map { |x| x.to_f }
    x1, y1, x2, y2 = (p1 + p2)
    r, g, b = 0, 128, 128
    puts "lc10 %s" % [r + 256 * g + 256 * 256 * b]
    r = hypot(x2 - x1, y2 - y1)
    w = ENV["w"].to_f
    d = hk * PI / 180
    puts "sc" + " %s %s" * 4 % [x1, y1, r, w, d, 0, 2 * PI, 100]
end
__END__

 

○set.bat

set %~1=%~2
if defined %~1 (
  echo ^%~2> %3
) else (
  if exist %3 (
    for /f "tokens=*" %%a in (%3) do set %~1=%%a
  )
)