外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。
tclshで線の端点に矢印を描く
:tclshで線の端点に矢印を描く
@echo off
for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
copy jwc_temp.txt myfiles > nul
more +%%n %0 | tclsh - > jwc_temp.txt
)
goto:eof
REM #jww
REM #1ln 線を指示してください
REM #bz
REM #e
#!この次の行からプログラムを書いてください
proc ptdist {pt1 pt2} {
lassign $pt1 x1 y1
lassign $pt2 x2 y2
return [expr hypot($x2 - $x1, $y2 - $y1)]
}
proc lnslope {ln} { #線の角度を返す
lassign $ln x1 y1 x2 y2
return [expr atan2($y2 - $y1, $x2 - $x1)]
}
proc polarto {pt r d} {
lassign $pt x y
return [list [expr $x + $r * cos($d)] [expr $y + $r * sin($d)]]
}
proc arrow {pt1 d {size 5} {xang 45} {xan2 120}} {
set l $size
set PI [expr acos(-1)]
set a [expr $xang * $PI / 180 / 2.0]
set pt2 [polarto $pt1 $l [expr $d - $a]]
set pt4 [polarto $pt1 $l [expr $d + $a]]
if {$xan2 == 180} {
set sl [concat $pt1 $pt2 $pt4]
puts [format "sl %s" $sl]
} else {
set c [expr cos($a) - sin($a) * tan((90.0 - $xan2 / 2.0) * $PI / 180)]
set pt3 [polarto $pt1 [expr $l * $c] $d]
set sl [concat $pt1 $pt2 $pt3 $pt4]
puts [format "sl %s" $sl]
}
}
set tcl_precision 16; #文字列を数値演算するとき有効桁数 16 (デフォルト 12)
set f [open myfiles]
foreach 0 [split [read $f] \n] {
switch -regexp -- $0 {
^hq { puts "bz"; continue }
^hp1ln { set pt [lrange $0 1 end] }
{^[ ]} {
lassign $0 x1 y1 x2 y2
set size 5; #矢印の長さ( 図寸 )
set xang 45; #矢印の交角( ゚ )
set xan2 120; #矢尻の交角( ゚ )
set d [lnslope $0]
set l1 [ptdist $pt [list $x1 $y1]]
set l2 [ptdist $pt [list $x2 $y2]]
set pm [expr {$l1 <= $l2} ? -1 : 1]
set p1 [expr {$pm == 1} ? {[list $x2 $y2]} : {[list $x1 $y1]}]
arrow $p1 $d [expr -$pm * $size] $xang $xan2
}
}
}
close $f