2, 3, 5, 7, 11, 13, 17, 19, 23, …and on toward infinity. Prime numbers are a part of mathematics which seduce most of us at some point in our lives to try and “solve them”. There is structure in them, but too little to be easily understandable, and too much to let go and consider them chaos.
Recently, my girlfriend got sucked into this madness. Luckily she is not trying to generate the next largest prime (which would need to have more than 22 Million digits, although I might have jinxed it now). Instead she is looking for order into chaos; leading to pen and paper graphs, evolving into excel worksheets being abused as ordinary bitmap pictures and finally mathematica applications for even more heavy lifting.
These last exercises came to a somewhat grinding halt when mathematica refused to generate a gif-animation (it just failed to do the job without providing any warning that something might have gone awry). However, because it could generate the separate frames without any issues, I was tempted to dig up an old fortran module which allowed me to generate gif images and animations. I remembered correctly that it was able to both read and write gif-images, and so, after 10 minutes of writing a small program (9 minutes remembering how things worked) and another 10 linking in all dependencies and fixing some inconsistencies, I had a working program for generating a gif animation from separate gif images.
program GifCombo use GIFImageModule; use typesmodule; implicit none character(len=255):: filename,basename integer :: imin, imax, nr, ios type(TGif):: AniGif, StatGif write(*,*) "Small program to combine a set of GIFs to make one animated gif." write(*,*) "Gif-filenames should be structured as GIFNAME_XX.gif ," write(*,*) "With GIFNAME the basename, and XX an integer number (without preceding zero's)." write(*,*) " > Provide the basename:" read(*,*) basename write(*,*) " > Provide the lower index:" read(*,*) imin write(*,*) " > Provide the higher index:" read(*,*) imax !The actual work call AniGif%initialize() do nr=imin,imax write(filename,'(I0)') nr filename=trim(basename)//"_"//trim(filename)//".gif" if (nr>imin) then call StatGif%initialize() call StatGif%read(filename,1,ios,.true.) call AniGif%addImage(int(StatGif%image(:,:,1),I_int)) call StatGif%free() else call AniGif%read(filename,1,ios,.true.) end if end do call AniGif%setGlobalDelayTime(30) !writing the result filename=trim(basename)//"_Animated.gif" call AniGif%write(filename) write(*,*) "This should have written an animated Gif to:",trim(filename) end program GifCombo
The initial test went smoothly. Using some simple gif images I created in paint, the resulting 4 frame animation is the one on the left (which is probably giving you a headache as you read this ;-).
The real test, with the single frame gifs Sylvia had prepared, was rather interesting: It failed miserably. Fortunately it also taught us the origin of the problem: mathematica was generating frames of different dimensions. And although this does not give rise to problems in the workbook or generated avi, it does kill an animated gif. After fixing this, also mathematica successfully generated the animated gif Sylvia wanted to see. Also my own small program was now able to perform the intended trick, although it showed that a different color-map was created for each frame by mathematica, something my own implementation did not handle well (we’ll fix that somewhere in the future).
The executable (including prerequisite dll’s) can be downloaded here.
If you do not suffer from epileptic seizures (or not yet), you could check out the results in the spoiler below.