-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
140 lines (130 loc) · 4.95 KB
/
app.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import numpy as np
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import dash_bootstrap_components as dbc
from lissajous import lissajous_knot, plot_curves
app = dash.Dash(external_stylesheets=[dbc.themes.DARKLY])
app.title = "Lissajous Knots"
server = app.server
app.layout = dbc.Container(
[
dbc.Row(
[
dbc.Col(
[
html.H2("Lissajous Knots"),
html.H5("Rinaldi Petrolli"),
html.A("[email protected]", href="mailto:[email protected]"),
],
width=True,
),
],
align="end",
),
html.Hr(),
dbc.Row(
[
dbc.Col(
[
html.Div(
[
html.H5("Parameters"),
html.P("A"),
dcc.Input(
id="a",
placeholder=3,
type='number',
value=3
),
html.P(""),
html.P("B"),
dcc.Input(
id="b",
placeholder=4,
type='number',
value=4,
),
html.P(""),
html.P("C"),
dcc.Input(
id="c",
placeholder=2,
type='number',
value=2,
),
html.P(""),
html.P("ϕ1 [0 to 2π]"),
dcc.Input(
id="phi0",
min=0, max=2 * np.pi, step=np.pi / 4,
type='range',
value=np.pi / 2,
),
html.P(""),
html.P("ϕ2 [0 to 2π]"),
dcc.Input(
id="phi1",
min=0, max=2 * np.pi, step=np.pi / 4,
type='range',
value=np.pi / 2,
),
html.P(""),
html.P("Number of points"),
dcc.Input(
id="n_points",
min=10, max=600, step=10,
type='range',
value=100,
),
],
),
html.Hr(),
html.H5("Reference"),
html.P("LISSAJOUS KNOTS - M. G. V. BOGLE, J. E. HEARST, V. F. R. JONES and L. STOILOV (1994)"),
html.P("A, B, C = 1, 2, 3..."),
html.P("x = cos (At + ϕ1)"),
html.P("y = cos (Bt + ϕ2)"),
html.P("z = cos (Ct)"),
html.P("with 0 < t < 2π"),
],
width=3,
),
dbc.Col(
[
dcc.Graph(id="display", style={"height": "80vh"}),
],
width=True,
),
]
),
html.Hr(),
html.P(
[
html.A(
"Source code",
href="https://github.com/rinaldipp/lissajous_knots",
),
]
),
],
fluid=True,
)
@app.callback(
[Output(component_id='display', component_property='figure')],
[Input(component_id='a', component_property='value'),
Input(component_id='b', component_property='value'),
Input(component_id='c', component_property='value'),
Input(component_id='phi0', component_property='value'),
Input(component_id='phi1', component_property='value'),
Input(component_id='n_points', component_property='value'),]
)
def update_graph(a, b, c, phi1, phi2, n_points):
phi1 = float(phi1)
phi2 = float(phi2)
n_points = int(n_points)
x, y, z, x_offset, y_offset, z_offset = lissajous_knot(a, b, c, phi1, phi2, n_points)
fig = plot_curves(x, y, z, x_offset, y_offset, z_offset)
return [fig]
if __name__ == "__main__":
app.run_server(debug=True)