Spaces:
Sleeping
Sleeping
kolibril13
commited on
Commit
•
cbb25bf
1
Parent(s):
16428a1
wave parcel idea
Browse files- pages/01_sine_widget.py +35 -8
pages/01_sine_widget.py
CHANGED
@@ -32,7 +32,7 @@ class TldrawSineWidget(ipyreact.ReactWidget):
|
|
32 |
style={{
|
33 |
position: "relative",
|
34 |
width: "800px",
|
35 |
-
height: "
|
36 |
}}
|
37 |
>
|
38 |
<Tldraw onMount={handleMount} onChange={e => console.log("hii")} />
|
@@ -49,15 +49,42 @@ float_value = solara.reactive(0)
|
|
49 |
|
50 |
@solara.component
|
51 |
def Page():
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
points = np.column_stack((x, y)).tolist()
|
57 |
-
TldrawSineWidget.element(points=points)
|
58 |
-
solara.Markdown(f"**Float value**: {float_value.value}")
|
59 |
-
solara.FloatSlider("Some float", value=float_value, min=0, max=4*np.pi, step=0.1)
|
60 |
|
61 |
with solara.Row():
|
62 |
solara.Button("Reset", on_click=lambda: float_value.set(0))
|
|
|
|
|
|
|
|
|
|
|
63 |
Page()
|
|
|
32 |
style={{
|
33 |
position: "relative",
|
34 |
width: "800px",
|
35 |
+
height: "450px",
|
36 |
}}
|
37 |
>
|
38 |
<Tldraw onMount={handleMount} onChange={e => console.log("hii")} />
|
|
|
49 |
|
50 |
@solara.component
|
51 |
def Page():
|
52 |
+
dispersion = "high" # "high", "low", "const"
|
53 |
+
def n(wj):
|
54 |
+
if dispersion == "high":
|
55 |
+
return 1 + wj * 0.1
|
56 |
+
if dispersion == "low":
|
57 |
+
return 1.1 - wj * 0.01
|
58 |
+
if dispersion == "const":
|
59 |
+
return 1
|
60 |
+
|
61 |
+
c = 1
|
62 |
+
num_of_waves = 121
|
63 |
+
start_w = 1
|
64 |
+
end_w = 7
|
65 |
+
x = np.linspace(-2, 10, 1001)
|
66 |
+
|
67 |
+
def g(x, t):
|
68 |
+
u1 = 0
|
69 |
+
for wj in np.linspace(start_w, end_w, num_of_waves):
|
70 |
+
u1 += np.exp(1j * (wj * n(wj) / c * x - t * wj))
|
71 |
+
return u1.real
|
72 |
+
|
73 |
+
ooo = 38
|
74 |
+
points = np.column_stack((x*50+ooo, g(x, float_value.value)+150)).tolist()
|
75 |
+
points = points[100:]
|
76 |
+
points[0] = [ooo-40, 0]
|
77 |
+
|
78 |
+
|
79 |
+
# solara.Markdown(" \psi(x, t) = \sum \limits_j C_j \cdot e^{\mathrm{i}( - k_j \cdot x + \omega_j \cdot t )}, \omega_j= \frac{k_j}{c(k_j)} $")
|
80 |
+
# solara.Markdown(f"**t**: {float_value.value}")
|
81 |
|
|
|
|
|
|
|
|
|
82 |
|
83 |
with solara.Row():
|
84 |
solara.Button("Reset", on_click=lambda: float_value.set(0))
|
85 |
+
solara.FloatSlider("Time t", value=float_value, min=0, max=4*np.pi, step=0.1)
|
86 |
+
TldrawSineWidget.element(points=points)
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
Page()
|