#!/bin/sh
set -eu

if [ $# = 0 ]
then
    1>&2 echo "Usage: $SELF [nbody...]";
    exit 1
fi

sed "1,/^exit$/d;" "$0" | xargs "$@" -t 1e-3 -s 2000000 -n 2000000000 -- > simple.dat

gnuplot <<EOF
set terminal gif animate delay 10
set output "|ffmpeg -hide_banner -loglevel error -stats -y -i - -row-mt 1 simple.webm"

set size square
set xrange [-50:10]
set yrange [-50:10]
set grid
unset key

steps = int(system("awk '/^$/ {i++} END { print (i/2)-1 }' simple.dat"))
do for [i=0:steps] {
	plot "simple.dat" index 0:i with dots, "" index i with points pointtype 7
}
EOF

exit
10,0;0,0;100
-10,0;0,0;200
0,10;0,0;300
0,-10;0,0;400

