日曜日, 10月 20, 2013

gnuplot とシェルスクリプトでベクトル動画 : vector animation by gnuplot and shellscript

gnuplot で 動きのあるベクトル描画


#!/bin/bash

echo "vector_plot_anim.sh"

##################################################
nDiv=20
OutputAnimFile="./output.gif"
TmpFilePrefix="./tmp"
Xmin="-1.25"
Xmax="1.25"
Ymin="-1.25"
Ymax=" 1.25"

##################################################
pi=`echo "scale=5; 4.0*a(1.0)" | bc -l`
dtheta=`echo "scale=5; 2.0*${pi}/${nDiv}" | bc -l`

echo "  nDiv : "${nDiv}
echo "    pi : "${pi}
echo "dtheta : "${dtheta}


##################################################
rm -f ${TmpFilePrefix}
theta=0.0
for i in `seq -w 1 ${nDiv}` ; do
    X=`echo "scale=5; c(${theta})" | bc -l`
    Y=`echo "scale=5; s(${theta})" | bc -l`
    echo 0.0 0.0 ${X} ${Y} > ${TmpFilePrefix}.tmp

    theta=`echo "scale=5; ${theta} + ${dtheta}" | bc -l`

    gnuplot << EOF
    set out "${TmpFilePrefix}${i}.gif"
    set size square
    set xrange [$Xmin:$Xmax]
    set yrange [$Ymin:$Ymax]
    set term gif
    set grid
    set pointsize 4
    plot "${TmpFilePrefix}.tmp" w vector pointtype 7 title ""
EOF
done


##################################################
convert -delay 10 -loop 0 ./${TmpFilePrefix}*.gif  ${OutputAnimFile}



とやると,以下の動画のように...



で,角度表示を入れたりする.

#!/bin/bash

echo "vector_plot_anim2.sh"

##################################################
nDiv=20
OutputAnimFile="./output.gif"
TmpFilePrefix="./tmp"
Xmin="-1.25"
Xmax="1.25"
Ymin="-1.25"
Ymax=" 1.25"

##################################################
pi=`echo "scale=5; 4.0*a(1.0)" | bc -l`
dtheta=`echo "scale=5; 2.0*${pi}/${nDiv}" | bc -l`

echo "  nDiv : "${nDiv}
echo "    pi : "${pi}
echo "dtheta : "${dtheta}


##################################################
rm -f ${TmpFilePrefix}
theta=0.0
for i in `seq -w 1 ${nDiv}` ; do
    X=`echo "scale=5; c(${theta})" | bc -l`
    Y=`echo "scale=5; s(${theta})" | bc -l`

    phase=`echo theta=${theta}`

    echo 0.0 0.0 ${X} ${Y} > ${TmpFilePrefix}.tmp

    gnuplot << EOF
    set out "${TmpFilePrefix}${i}.gif"
    set size square
    set xrange [$Xmin:$Xmax]
    set yrange [$Ymin:$Ymax]
    set label 1 at screen 0.25    ,0.15 "${phase}"
    set term gif
    set grid
    set pointsize 4
    plot "${TmpFilePrefix}.tmp" w vector pointtype 7 title ""
EOF

    theta=`echo "scale=5; ${theta} + ${dtheta}" | bc -l`

done


##################################################
convert -delay 10 -loop 0 ./${TmpFilePrefix}*.gif  ${OutputAnimFile}





0 件のコメント: