diff options
author | Ian Jauslin <jauslin@ias.edu> | 2018-04-04 06:21:21 +0000 |
---|---|---|
committer | Ian Jauslin <jauslin@ias.edu> | 2018-04-04 06:21:21 +0000 |
commit | f950c74e38d120e42637983d504f85843a63e95d (patch) | |
tree | eb2ded33fc156da7adaf096c3816432b4262c8d4 /figs/ising.fig/ising.py |
Diffstat (limited to 'figs/ising.fig/ising.py')
-rw-r--r-- | figs/ising.fig/ising.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/figs/ising.fig/ising.py b/figs/ising.fig/ising.py new file mode 100644 index 0000000..8dd1447 --- /dev/null +++ b/figs/ising.fig/ising.py @@ -0,0 +1,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) |