Skip to content

Commit 7dc61b0

Browse files
committed
One more slider
1 parent 5bd5415 commit 7dc61b0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

examples/sliders.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function figure_eight_path(A, B, C, D, x0, y0, theta, num_points)
1414
return x_final, y_final
1515
end
1616

17-
A = 20.0 # width of the figure-eight
17+
A = Observable(20.0) # width of the figure-eight
1818
B = Observable(10.0) # height of the figure-eight
1919
C = Observable(0.0) # size of right part of the figure-eight
2020
D = Observable(0.0) # asymmetry factor
@@ -23,18 +23,18 @@ y0 = 25.0 # center y-coordinate
2323
theta = 0*π/6 # rotation angle in radians
2424
num_points = 200
2525

26-
function figure_eight_y(B, C, D)
26+
function figure_eight_y(A, B, C, D)
2727
x, y = figure_eight_path(A, B, C, D, x0, y0, theta, num_points)
2828
return y
2929
end
3030

31-
function figure_eight_x(B, C, D)
31+
function figure_eight_x(A, B, C, D)
3232
x, y = figure_eight_path(A, B, C, D, x0, y0, theta, num_points)
3333
return x
3434
end
3535

36-
y = @lift(figure_eight_y($B, $C, $D))
37-
x = @lift(figure_eight_x($B, $C, $D))
36+
y = @lift(figure_eight_y($A, $B, $C, $D))
37+
x = @lift(figure_eight_x($A, $B, $C, $D))
3838

3939
# Create the figure and axis
4040
fig = Figure()
@@ -44,29 +44,32 @@ ax = Axis(fig[1, 1], xlabel = "azimuth [°]", ylabel = "elevation [°]",
4444
# Plot the sine wave
4545
lineplot = lines!(ax, x, y)
4646
ylims!(ax, 10, 40)
47+
xlims!(ax, -30, 30)
4748

4849
# Create sliders for amplitude and frequency
4950
sg = SliderGrid(
5051
fig[2, 1],
52+
(label = "A", range = 10:0.01:30.0, startvalue = 20.0),
5153
(label = "B", range = 5:0.01:20.0, startvalue = 10.0),
5254
(label = "C", range = -2.0:0.01:2.0, startvalue = 0.0),
5355
(label = "D", range = -3:0.01:3.0, startvalue = 0.0)
5456
)
5557

5658
# Connect sliders to observables
5759
on(sg.sliders[1].value) do val
58-
B[] = val
60+
A[] = val
5961
end
6062

6163
on(sg.sliders[2].value) do val
62-
C[] = val
64+
B[] = val
6365
end
6466

6567
on(sg.sliders[3].value) do val
66-
D[] = val
68+
C[] = val
6769
end
6870

69-
# Optional: keep axis limits stable if amplitude changes a lot
70-
# ax.ylims = (-2, 2) # or use autolimits! if you prefer dynamic limits
71+
on(sg.sliders[4].value) do val
72+
D[] = val
73+
end
7174

7275
fig

0 commit comments

Comments
 (0)