1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/usr/bin/env python3
import random
from math import *
# size of the grid
L=8
# draw spins, probability of reds: p, only fill up to H
def draw_spins(p, H, file_desc):
for i in range(L):
for j in range(H):
if(random.random()<p):
print("\\fill[color=red]("+str(i)+","+str(j)+")circle(0.2);", file=file_desc);
else:
print("\\fill[color=blue]("+str(i)+","+str(j)+")circle(0.2);", file=file_desc);
print("\\draw("+str(i)+","+str(j)+")circle(0.2);", file=file_desc);
# init tikz file
def init_tikz(filename):
file_desc=open(filename,"w")
print("\\documentclass{standalone}\n\n\\usepackage{tikz}\n\\usepackage{ising}\n\\usetikzlibrary{decorations.pathmorphing}\n\n\\begin{document}\n\\begin{tikzpicture}\n\n", file=file_desc)
return(file_desc)
# close tikz file
def close_tikz(file_desc):
print("\\end{tikzpicture}\n\\end{document}", file=file_desc)
file_desc.close()
# files
ising=init_tikz("ising.tikz.tex")
print("\\grid{"+str(L-1)+"}{"+str(L-1)+"}{(0,0)}\n", file=ising)
draw_spins(0.5,L,ising)
close_tikz(ising)
ising_blue=init_tikz("ising_blue.tikz.tex")
print("\\grid{"+str(L-1)+"}{"+str(L-1)+"}{(0,0)}\n", file=ising_blue)
draw_spins(0.1,L,ising_blue)
close_tikz(ising_blue)
ising_red=init_tikz("ising_red.tikz.tex")
print("\\grid{"+str(L-1)+"}{"+str(L-1)+"}{(0,0)}\n", file=ising_red)
draw_spins(0.9,L,ising_red)
close_tikz(ising_red)
transfer1=init_tikz("transfer1.tikz.tex")
print("\\grid{"+str(L-1)+"}{"+str(L-1)+"}{(0,0)}\n", file=transfer1)
draw_spins(0.5,1,transfer1)
close_tikz(transfer1)
transfer2=init_tikz("transfer2.tikz.tex")
print("\\grid{"+str(L-1)+"}{"+str(L-1)+"}{(0,0)}\n", file=transfer2)
draw_spins(0.5,2,transfer2)
close_tikz(transfer2)
|