forked from TomTranter/JellyBaMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogo.py
105 lines (87 loc) · 2.58 KB
/
logo.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import numpy as np
from matplotlib import patches, path, pyplot as plt
import ecm
class RoundedPolygon(patches.PathPatch):
def __init__(self, xy, pad, **kwargs):
p = path.Path(*self.__round(xy=xy, pad=pad))
super().__init__(path=p, **kwargs)
def __round(self, xy, pad):
n = len(xy)
for i in range(0, n):
x0, x1, x2 = np.atleast_1d(xy[i - 1], xy[i], xy[(i + 1) % n])
d01, d12 = x1 - x0, x2 - x1
d01, d12 = d01 / np.linalg.norm(d01), d12 / np.linalg.norm(d12)
x00 = x0 + pad * d01
x01 = x1 - pad * d01
x10 = x1 + pad * d12
if i == 0:
verts = [x00, x01, x1, x10]
else:
verts += [x01, x1, x10]
codes = [path.Path.MOVETO] + n * [
path.Path.LINETO,
path.Path.CURVE3,
path.Path.CURVE3,
]
return np.atleast_1d(verts, codes)
alpha = 0.5
c1 = np.array([75 / 255, 139 / 255, 190 / 255, alpha]) # Cyan-Blue Azure
c1e = np.array([48 / 255, 105 / 255, 152 / 255, alpha]) # Lapis Lazuli
c2 = np.array([1, 232 / 255, 115 / 255, alpha]) # Shandy
c2e = np.array([1, 212 / 255, 59 / 255, alpha]) # Sunglow
c3 = np.array([100 / 255, 100 / 255, 100 / 255, alpha]) # Granite Gray
# Test
xy = np.array(
[
(0, 0),
(0.25, 0),
(0.5, -0.25),
(0.75, 0),
(1, 0),
(1, 0.25),
(1.25, 0.5),
(1, 0.75),
(1, 1),
(0.75, 1),
(0.5, 1.25),
(0.25, 1),
(0, 1),
(0, 0.75),
(-0.25, 0.5),
(0, 0.25),
]
)
r = 1
dr = 0.5
ntheta = 36 * 4
n = 3
(x1, y1, r1, pos1) = ecm.spiral(r, dr, ntheta, n)
(x2, y2, r2, pos2) = ecm.spiral(r + dr / 2, dr, ntheta, n)
(x3, y3, r3, pos3) = ecm.spiral(r + dr, dr, ntheta, n)
xy12 = np.vstack((np.hstack((x1, x2[::-1])), np.hstack((y1, y2[::-1])))).T
rp1 = RoundedPolygon(xy=xy12, pad=dr / 10, facecolor=c1, edgecolor=c1e, lw=1)
xy23 = np.vstack((np.hstack((x2, x3[::-1])), np.hstack((y2, y3[::-1])))).T
rp2 = RoundedPolygon(xy=xy23, pad=0.1, facecolor=c2, edgecolor=c2e, lw=1)
fig, ax = plt.subplots(figsize=(10, 10))
ax.add_patch(rp1)
ax.add_patch(rp2)
ax.set_aspect(1)
ax.axis("off")
l = x3.max() * 1.1
ax.set_xlim(-l, l)
ax.set_ylim(-l, l)
# OpenPNM project
project, arc_edges = ecm.make_spiral_net(
Nlayers=n,
dtheta=10,
spacing=dr / 2,
inner_r=1,
pos_tabs=[0],
neg_tabs=[-1],
length_3d=1,
tesla_tabs=False,
)
net = project.network
ecm.plot_topology(net, ax=ax)
plt.tight_layout()
plt.savefig("jellybamm_logo.png", transparent=True)