Ising model try

Function:

(*If test==o, keep value, if test==1, switch*)
Switchh[test_,valueinmatrix_]:=Module[{output},
output=Abs[valueinmatrix-test]
]

(* create a matrix nxn of random 1 or 0*)
Createlistrandom[n_]:=Module[{},
Table[RandomInteger[1],{i,1,n},{j,1,n}]
]

(* create a matrix nxn half/half*)
Createlisthalf[n_]:=Module[{},
Table[If[i<n/2,0,1],{i,1,n},{j,1,n}]
]

(* create a matrix nxn of value*)
Createlistchoice[n_,value_]:=Module[{},
Table[value,{i,1,n},{j,1,n}]
]

(*copy first/last raw/line to the matrix to make it borderless*)
Addrows[Matrix_]:=Module[{Newmatrix,m},
m=Length[Matrix];
Newmatrix=Table[
Insert[Insert[Matrix[[i]],Last[Matrix[[i]]],1],First[Matrix[[i]]],-1],
{i,1,m}];
Newmatrix=Insert[Newmatrix,Last[Newmatrix],1];
Newmatrix=Insert[Newmatrix,Newmatrix[[2]],-1]
]

(*Calcul the probability to suceed in change*)
Changeprob[Matrix_,i_,j_,interaction_,field_]:=Module[
{nbneigbourg,proba},
nbneigbourg=Matrix[[i-1,j]]+Matrix[[i+1,j]]+Matrix[[i,j+1]]+Matrix[[i,j-1]];
If[Matrix[[i,j]]==0,proba= Max[(nbneigbourg-2)*interaction+field,0.1]];
If[Matrix[[i,j]]==1,proba=Max[(4-nbneigbourg-2)*interaction-field,0.1]];
proba
]

(*create the next matrix*)
Newstate[Matrix_,interaction_,field_,Tau_]:=Module[{m,newMatrix,Matrixtest,switchornot,proba},
m=Length[Matrix];
newMatrix=Matrix;
Matrixtest=Addrows[Matrix];
Do[
Do[{
proba=Exp[-1/(Tau*Changeprob[Matrixtest,i+1,j+1,interaction,field])];
switchornot=RandomChoice[{proba,2-proba}->{1,0}];
newMatrix[[i,j]]=Switchh[switchornot,Matrix[[i,j]]];
}
,{j,1,m}]
,{i,1,m}];
newMatrix
]

Drawfunction[Matrix_,position_]:=Graphics[{RGBColor[Matrix[[position[[1]],position[[2]]]],0,0],Disk[position,0.5]},ImageSize-> Large];

Test

Matrix=Createlist[10];

Matrix//MatrixForm;

Matrix=Newstate[Matrix,0.25,1];

Count[Matrix,u_/;u==0,2]

Drawfunction[Matrix_,position_]:=Graphics[{RGBColor[Matrix[[position[[1]],position[[2]]]],0,0],Disk[position,0.5]}];

Initialisation

Texttoshow1=Text[Style["T: low",FontSize->20],{Length[Matrix]+2.8,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation: strong",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: strong",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];

(*random start*)
Initialisation1[sizeof_]:=Module[{},
Matrix=Createlistrandom[sizeof];
]
(*Red start*)

Initialisation2[sizeof_]:=Module[{},
Matrix=Createlistchoice[sizeof,0];
]

(*half start*)
Initialisation3[sizeof_]:=Module[{},
Matrix=Createlisthalf[sizeof];
]

Fix[sizeof_,int_,fields_,Taus_]:=Module[{},
interaction=int;
field=fields;
Tau=Taus;
Rec=Graphics[{Red,Table[Rectangle[{i+0.25,-5},{i+0.75,-2}],{i,0,sizeof}]}];
Pointtri=Table[{{i,-2},{i+1,-2},{i+0.5,-1}},{i,0,sizeof}];
Triangles=Graphics[{Red,Triangle[Pointtri]}];]

Dynamic[Tau]

Run

Initialisation2[25];Fix[25,4,1.5,4];

Initialisation2[25];Fix[25,4,4,6];

Initialisation3[25];Fix[25];

Fix[];

Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.1]},25]

Dynamic@Show[
Table[Drawfunction[Matrix,{i,j}],{i,1,Length[Matrix]},{j,1,Length[Matrix]}],
Graphics[Text[Style[ToString@IntegerPart[(Count[Matrix,u_/;u==0,2] 100/Length[Matrix]^2)]<>"% of down spin",FontSize->20],{Length[Matrix]/2,Length[Matrix]+2}]],
Rec,
Triangles,
Graphics[Texttoshow1],
Graphics[Texttoshow2],
Graphics[Texttoshow3],
Graphics[Text[Style["magnetic field direction",FontSize->20],{Length[Matrix]/2,-6.2}]]
]

Run:

timess=5;
testxx=5;

Do[

Texttoshow1=Text[Style["T: ",FontSize->20],{Length[Matrix]+3.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation: ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];

(*show the 3 cases*)
Initialisation1[25];
Fix[25];
Pause[20];

Initialisation2[25];
Fix[25];
Pause[20];

Initialisation3[25];
Fix[25];
Pause[30];

(*high T no interaction*)
Initialisation2[25];Fix[25,0,0,3];
Texttoshow1=Text[Style["T:medium ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation:0 ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field:0 ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[10];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},25];

Initialisation2[25];Fix[25,0,0,10];
Texttoshow1=Text[Style["T:high ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation:0 ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field:0 ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[timess];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},25];

(*high T and interaction*)
Initialisation2[25];Fix[25,4,0,3];
Texttoshow1=Text[Style["T:medium ",FontSize->20],{Length[Matrix]+5.3,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation: yes ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: no ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[15];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},25];

(*higher T and interaction*)
Initialisation2[25];Fix[25,4,0,10];
Texttoshow1=Text[Style["T:high ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation: yes ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: no ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[3];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},25];
Pause[20]


(* T and interaction*)
Initialisation3[25];Fix[25,10,0,3];
Texttoshow1=Text[Style["T:low ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation: yes",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: no ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[10];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},25];
Initialisation3[25];Fix[25,10,0,4.5];
Texttoshow1=Text[Style["T:medium ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation: yes ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: no ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[3];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},25];
Initialisation3[25];Fix[25,10,0,10];
Texttoshow1=Text[Style["T:high ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation: yes ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: no ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[3];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},25];
Pause[10];

(*magnetic field weak and strong *)
Initialisation1[25];Fix[25,4,0.1,6];
Texttoshow1=Text[Style["T:low ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation:yes  ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: small ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[10];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},25];
Pause[5];
Initialisation1[25];Fix[25,4,4,6];
Texttoshow1=Text[Style["T:low ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation:yes  ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: yes ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[5];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},45];


Initialisation2[25];Fix[25,4,0.1,6];
Texttoshow1=Text[Style["T:low ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation:yes  ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: yes ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[5];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},45];
Pause[5];
Initialisation2[25];Fix[25,4,4,6];
Texttoshow1=Text[Style["T:low ",FontSize->20],{Length[Matrix]+5.5,Length[Matrix]/2}];
Texttoshow2=Text[Style["Interation:yes  ",FontSize->20],{Length[Matrix]+6,Length[Matrix]/2-2}];
Texttoshow3=Text[Style["Magn. field: yes ",FontSize->20],{Length[Matrix]+6.5,Length[Matrix]/2+2}];
Pause[5];
Do[{Matrix=Newstate[Matrix,interaction,field,Tau];
Pause[0.5]},45];



,1];