-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.py
More file actions
71 lines (62 loc) · 2.42 KB
/
Copy pathnode.py
File metadata and controls
71 lines (62 loc) · 2.42 KB
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
66
67
68
69
70
71
from random import choice
class Node:
def __init__(self,x,y,num):
self.x = x
self.y = y
self.num = num
def display(self):
fill(0)
ellipse(self.x,self.y,10,10)
def connect(self,other):
strokeWeight(1)
line(self.x,self.y,
other.x,other.y)
nodes = ['placeholder']#so the first node will be 1
mirrornodes = ['placeholder']
#list for connections between nodes
connections = [[1,2],[1,4],
[2,3],[2,4],[2,5],
[3,5],[3,7],
[4,5],[4,6],
[5,6],[5,7],
[6,7],[6,8],
[7,8],[7,9],
[8,9]]
class Grid:
def __init__(self,sz):
#create the nodes in the grid
nodes.append(Node(0,0,1))
nodes.append(Node(0,-sz,2))
nodes.append(Node(0,-2*sz,3))
nodes.append(Node(sz/2.0,-sz/2.0,4))
nodes.append(Node(0.5*sz,-1.5*sz,5))
nodes.append(Node(sz,-sz,6))
nodes.append(Node(sz,-2*sz,7))
nodes.append(Node(1.5*sz,-1.5*sz,8))
nodes.append(Node(2*sz,-2*sz,9))
#create the nodes which mirror over the diagonal line
mirrornodes.append(Node(0,0,1))
mirrornodes.append(Node(sz,0,2))
mirrornodes.append(Node(2*sz,0,3))
mirrornodes.append(Node(sz/2.0,-sz/2.0,4))
mirrornodes.append(Node(1.5*sz,-0.5*sz,5))
mirrornodes.append(Node(sz,-sz,6))
mirrornodes.append(Node(2*sz,-sz,7))
mirrornodes.append(Node(1.5*sz,-1.5*sz,8))
mirrornodes.append(Node(2*sz,-2*sz,9))
#randomly choose which nodes are connecting
self.connectChoice = [choice([0,1]) for x in range(15)]
def connect(self):
#for every node that's connecting:
for i,c in enumerate(self.connectChoice):
if c == 1: #if the connection is active
#connect the first node in the 2-list with the second
nodes[connections[i][0]].connect(nodes[connections[i][1]])
#also connect the reflections of those nodes
mirrornodes[connections[i][0]].connect(mirrornodes[connections[i][1]])
def display(self):
#copy the upper right quadrant
# to all 4 quadrants by rotating
for i in range(4):
rotate(radians(90*i))
self.connect()