Animating Alberto Garcia-Alvarez’s Phenakistoscopes using Magic

Tim Melville Gallery had an exhibition of Alberto Garcia-Alvarez’s work. I love the strong and bold colours. I guess with circles and a subject of ‘Time’ it was hard for me not to be enamoured. I explained to Tim that it would be easy to take the static images of the Phenakistoscopes and turn them into a movie to show what they really looked like if they were being used as intended. He said for me to try it and this story is the outcome.

With a little messing about, I managed this with the minimum of tools. Just a CMD batch file to loop through the commands, ImageMagick commands, and Gimp to find the centre and size of the circles.

History

To help with the various names for this type of early animation these are the links to the various types you might already know:

Gimp

Using Gimp and the Ellipse Select with Fixed Aspect Ratio 1:1, and Expand from centre, the key measurements can be found.

From this centre position/x,y and the circle size/diameter was found.

CMD Batch File

The other parameters to the script are the filename and the number of degrees in each rotation of the animation.

SET CIRCLEPOSX=1007
SET CIRCLEPOSY=986
SET CIRCLEDI=1867
SET FILE=green
SET EXT=jpg
SET ANGLE10K=300000

With these the other values could be calculated: radius, crop rectangle. Note the method for doing maths in a SET command is to use the /a option.

SET /a CIRCLEX="(!CIRCLEPOSX! * 2 + !CIRCLEDI!) / 2"
SET /a CIRCLEY="(!CIRCLEPOSY! * 2 + !CIRCLEDI!) / 2"
SET /a CIRCLER="!CIRCLEDI! / 2"
SET /a COUNT="(3* 3600000 / !ANGLE10K!) - 1"

SET /a CROP="CIRCLER * 110 / 100
SET /a CROPX="CIRCLEX - CROP / 2"
SET /a CROPY="CIRCLEY - CROP + (CIRCLER * 5 /100)"

There is no formatting available to pad these SET variables and the frames generated needed padded numeric values so they could be supplied to ffmpeg. Hence the prepending 0000 and then grabbing the last ~-4 letters, resulting in integers padded with 0 to a width of 4.

SET "LONGN=0000%%N"
SET PADN=!LONGN:~-4!

Also, the maths available in the SET /a command does not include floating point numbers, just integers. To get fractional angles the maths was done with fixed point integers. This is not needed for the case when the angle is 30 degrees, but for the case where there were 19 images on the disc 18.9474 was needed.

SET /a ROTATE="!ANGLE10K! * %%N"
SET ROTATEFRACTION=!ROTATE:~-4!
SET ROTATEDECIMAL=!ROTATE:~-9,-4!

The ~-9,-4 selects from the end of string, the -9th to -4th characters.

ImageMagick Magic

Step one is to create a mask that is the circle that is to be rotated. This is done using the command like this:

magick green.jpg 
    -fill black 
    -draw "rectangle 0,0 10000,10000" 
    -fill white 
    -draw "circle 1940,1919 1940,986"
    mask.png
Mask image with white to replace and black to keep

Note the unusual format for the circle values. Check the documentation here to see why.

Then the original image is rotated using ScaleRotateTranslate and composited back into the original image using the mask.

magick green.jpg -distort ScaleRotateTranslate "1940,1919 .0" temp.png
magick green.jpg temp.png mask.png -composite 0000.green.full.png

Once the loop is done to gather a series of images each numbered, 0000, 0001, 0002… they can be converted into a movie (MPG and x264 encoding) using ffmpeg.

ffmpeg 
    -framerate 10 
    -i "%04d.green.full.png" 
    -vf scale="1024:-1" 
    -c:v libx264 
    -y 
    green.full.mp4

The Full Script

@ECHO off
SETLOCAL EnableDelayedExpansion

SET CIRCLEPOSX=1007
SET CIRCLEPOSY=986
SET CIRCLEDI=1867
SET FILE=green
SET EXT=jpg
SET ANGLE10K=300000

SET /a CIRCLEX="(!CIRCLEPOSX! * 2 + !CIRCLEDI!) / 2"
SET /a CIRCLEY="(!CIRCLEPOSY! * 2 + !CIRCLEDI!) / 2"
SET /a CIRCLER="!CIRCLEDI! / 2"
SET /a COUNT="(3* 3600000 / !ANGLE10K!) - 1"

SET /a CROP="CIRCLER * 110 / 100
SET /a CROPX="CIRCLEX - CROP / 2"
SET /a CROPY="CIRCLEY - CROP + (CIRCLER * 5 /100)"

MKDIR temp

echo magick !FILE!.!EXT! -fill black -draw "rectangle 0,0 10000,10000" -fill white -draw "circle !CIRCLEX!,!CIRCLEY! !CIRCLEX!,!CIRCLEPOSY!" temp\mask.png 

FOR /L %%N IN (0,1,!COUNT!) DO (
	ECHO %%N
	SET /a ROTATE="!ANGLE10K! * %%N"
	SET ROTATEFRACTION=!ROTATE:~-4!
	SET ROTATEDECIMAL=!ROTATE:~-9,-4!
	SET "LONGN=0000%%N"
	SET PADN=!LONGN:~-4!
	echo magick !FILE!.!EXT! -distort ScaleRotateTranslate "!CIRCLEX!,!CIRCLEY! !ROTATEDECIMAL!.!ROTATEFRACTION!" temp\temp.png
	echo magick temp\temp.png -crop !CROP!x!CROP!+!CROPX!+!CROPY! temp\!PADN!.!FILE!.crop.png
	echo magick !FILE!.!EXT! temp\temp.png temp\mask.png -composite temp\!PADN!.!FILE!.full.png
)
echo ffmpeg -framerate 10 -i "temp\%%04d.!FILE!.crop.png"  -vf scale="1024:-1"  -c:v libx264 -y !FILE!.crop.mp4
echo ffmpeg -framerate 10 -i "temp\%%04d.!FILE!.full.png"  -vf scale="1024:-1"  -c:v libx264 -y !FILE!.full.mp4
echo ffmpeg -framerate 10 -i "temp\%%04d.!FILE!.crop.png"  -c:v libx264 -y !FILE!.crop.large.mp4
echo ffmpeg -framerate 10 -i "temp\%%04d.!FILE!.full.png"  -c:v libx264 -y !FILE!.full.large.mp4

The Final Results

Green
Green Cropped
Rainbow
Rainbow Cropped
Orange
Orange Cropped
Grey
Grey Cropped
White
White Cropped
Cream
Cream Cropped
Brown

Brown Cropped
Blue
Blue Cropped
Black
Black Cropped
Red
Red Cropped

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.