-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualizer.py
More file actions
90 lines (76 loc) · 2.73 KB
/
Copy pathvisualizer.py
File metadata and controls
90 lines (76 loc) · 2.73 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
import numpy as np
class Frame():
def __init__(self, particles):
self.x = np.ndarray(0)
self.y = np.ndarray(0)
self.z = np.ndarray(0)
if len(particles):
coords = list(map(lambda p: p.coords, particles))
coords = np.asarray(coords)
self.x, self.y, self.z = coords.swapaxes(0, 1)
class Visualizer():
def __init__(self, polyhedron, size=6):
self.frames = []
self.size = size
vx, vy, vz = np.rot90(polyhedron.vertices)[::-1]
i, j, k = [], [], []
for face in polyhedron.faces:
for a in range(1, len(face) - 1):
i.append(face[0])
j.append(face[a])
k.append(face[a + 1])
self.poly = go.Mesh3d(
x=vx,
y=vy,
z=vz,
colorbar_title='z',
colorscale=((0, 'grey'),
(0.5, 'mediumturquoise'),
(1, 'magenta')),
intensity=np.random.rand(len(polyhedron.vertices)),
i=i,
j=j,
k=k,
opacity=0.7,
name='y',
showscale=True)
def add_frame(self, particles, simulation_map): # TODO add simulation_map
self.frames.append(Frame(particles))
def create(self, i):
frame = self.frames[i]
return (self.poly, go.Scatter3d(
x=frame.x,
y=frame.y,
z=frame.z,
mode='markers',
marker=dict(size=self.size, color='yellow')))
def redraw(self):
fig = go.Figure(data=self.create(0),
layout=go.Layout(
plot_bgcolor='rgba(0,0,0,0)',
xaxis=dict(range=(0, 5), autorange=False),
yaxis=dict(range=(0, 5), autorange=False),
title="Physarum Polycephalum",
updatemenus=[dict(
type="buttons",
buttons=[dict(label="grow",
method="animate",
args=[None, {"frame": {"duration": 0}}]
)])]),
frames=[go.Frame(data=self.create(i)) for i in range(len(self.frames))])
fig.layout.plot_bgcolor = '#DCDCDC'
fig.layout.paper_bgcolor = '#fff'
fig.update_layout(
scene=dict(
xaxis=dict(showticklabels=False),
yaxis=dict(showticklabels=False),
zaxis=dict(showticklabels=False),
)
)
fig.update_scenes(xaxis_title_text="")
fig.update_scenes(yaxis_title_text="")
fig.update_scenes(zaxis_title_text="")
fig.show()