Ian Jauslin
summaryrefslogtreecommitdiff
blob: 2bc4d9cb064fd3af9e6d158d5689ede39d725229 (plain)
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
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3

from math import *
import random

# size of space (must be int)
L=30
# number of particles
N=int(L*L/2*0.97)

# check whether two diamonds overlap
def check_overlap(x1,x2):
    if(sqrt((x1[0]-x2[0])**2+(x1[1]-x2[1])**2)<=1):
        return(True)
    return(False)

# configuration
config=[]

# put particles on odd lattice manually
for i in range(4):
    for j in range(4):
        if (i!=2 or j!=1):
            config.append([2*int(L/2/2)+1+i+j,2*int(L/2/2)+i-j])

# add particles
while len(config)<N:
    # random position
    # even sublattice
    if(random.random()<0.5):
        x=[2*random.randint(0,int(L/2)), 2*random.randint(0,int(L/2))]
    else:
        x=[2*random.randint(0,int(L/2))+1, 2*random.randint(0,int(L/2))+1]
    # check it does not interfere with other particles
    fine=True
    for part in config:
        if(check_overlap(part,x)):
            fine=False
            break
    if fine:
        config.append(x)

print(r'''\documentclass{standalone}
\usepackage{tikz}
\usepackage{shapes}

\begin{document}
\begin{tikzpicture}
\grid{'''+str(L+3)+'}{'+str(L+3)+'''}{(-1,-1)}
''')

for i in range(len(config)):
    part=config[i]
    # different colors for even and odd
    if i<15:
        # replace %1% later
        print(r'\diamond{%1%}{('+str(part[0])+','+str(part[1])+')}')
    else:
        # replace %2% later
        print(r'\diamond{%2%}{('+str(part[0])+','+str(part[1])+')}')

print(r'''
\end{tikzpicture}
\end{document}
''')