2D Graphics

This page shows how to make 2D snapshots and animations of Ising-like spin models in simulation.

(You can see the gif animation by clicking on the figures)

2D Ising model at critical temperature Tc~2.27 using cluster (left) and single flip (right) algorithm.

1. One can first write each snapshot in a *.pbm file. e.g.

snapshot1.pbm

snapshot2.pbm

snapshot3.pbm

......

snapshotn.pbm

2. convert each *pbm file into *.gif format using command

convert aaa.pbm bbb.gif

If there are many snapshots to be converted, one can use the following script, which converts 1000 snapshots indexed from 0 to 999.

***************************************

#!/bin/tcsh

#

set t = 0

set dt = 1

set tmax = 1000

while ($t < $tmax)

convert snapshot${t}.pbm snapshot${t}.gif

@ t = $t + $dt

end

exit

***************************************

3. make one gif format animation file from the gif snapshots (here is an example of 10 snapshots)

***************************************

#!/bin/tcsh

#

rm animation.gif

convert -delay 2 snapshot0.gif snapshot1.gif snapshot2.gif snapshot3.gif snapshot4.gif snapshot5.gif

snapshot6.gif snapshot7.gif snapshot8.gif snapshot9.gif -loop 0 animation.gif

exit

***************************************

"-delay 2" controls the time interval for each snapshot

"-loop 0" means the animation does not repeat for another cycle.

If you have hundreds and thousands of snapshots, you might want to use some code to generate the above animation generating script rather than input all the name of the snapshots manually. Here is an example of a C code doing such a job.

***************************************

//write bash script to generate animation from gif snapshot

// Kai Zhang, Duke University, 2010

#include <stdio.h>

#include <stdlib.h>

int main(void)

{

int i;

int imax;

int di;

int dt;

FILE *fp;

fp=fopen("animationscript","w");

printf("write bash script for animation command\n");

printf("MAX shopshot number: ");

scanf("%d",&imax);

printf("shopshot increment number: ");

scanf("%d",&di);

printf("movie time increment: ");

scanf("%d",&dt);

fprintf(fp,"#!/bin/tcsh\n");

fprintf(fp,"#\n");

fprintf(fp,"rm animation.gif\n");

fprintf(fp,"convert -delay %d ",dt);

for(i=0;i<imax;i+=di)

fprintf(fp,"snapshot%d.gif ",i);

fprintf(fp," -loop 0 animation.gif\n");

fprintf(fp,"exit");

fclose(fp);

return 0;

}

***************************************

or use the short form

convert -delay 2 snapshot*.gif -loop 0 animation.gif