#!/bin/sh
#
# Create a rotating figure using affine transformations
# Some alpha composition is used to crop the result to the original size.
#
command='convert -delay 10 koala.gif -extent 74x74'
command="$command -background white -gravity center -compose Src"

for i in `seq 5 5 360`; do
  c=`perl -e "print cos($i*atan2(1,1)/45)"`  # cosine of angle
  s=`perl -e "print sin($i*atan2(1,1)/45)"`  # sine of angle
  sm=`perl -e "print -($s)"`                   # negative sine of angle
  command="$command \\( -clone 0 -affine $c,$s,$sm,$c,0,0 -transform +repage "
  command="$command -clone 0 +swap -composite \\)"
done

command="$command -delete 0 -loop 0 animated_affine_rot.gif"

eval $command

chmod 644 animated_affine_rot.gif
