Skip to content

Commit 769e433

Browse files
committed
Example sliders.jl working fine now
1 parent fd5cc5d commit 769e433

File tree

1 file changed

+15
-9
lines changed

1 file changed

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

17-
# Example usage:
1817
A = 10.0 # width of the figure-eight
1918
B = 5.0 # height of the figure-eight
20-
C = Observable(1.0) # size of right part of the figure-eight
21-
D = Observable(1.0) # asymmetry factor
19+
C = Observable(0.0) # size of right part of the figure-eight
20+
D = Observable(0.0) # asymmetry factor
2221
x0 = 0.0 # center x-coordinate
2322
y0 = 0.0 # center y-coordinate
2423
theta = 0*π/6 # rotation angle in radians
2524
num_points = 200
2625

27-
# Define the x range
28-
x = LinRange(0, 6π, 500)
26+
function figure_eight_y(C, D)
27+
x, y = figure_eight_path(A, B, C, D, x0, y0, theta, num_points)
28+
return y
29+
end
30+
31+
function figure_eight_x(C, D)
32+
x, y = figure_eight_path(A, B, C, D, x0, y0, theta, num_points)
33+
return x
34+
end
2935

30-
# Observable for the y values
31-
y = @lift($C .* sin.($D .* x))
36+
y = @lift(figure_eight_y($C, $D))
37+
x = @lift(figure_eight_x($C, $D))
3238

3339
# Create the figure and axis
3440
fig = Figure()
@@ -40,8 +46,8 @@ lineplot = lines!(ax, x, y)
4046
# Create sliders for amplitude and frequency
4147
sg = SliderGrid(
4248
fig[2, 1],
43-
(label = "C", range = 0.0:0.01:2.0, startvalue = 1.0),
44-
(label = "D", range = 0.5:0.01:3.0, startvalue = 1.0)
49+
(label = "C", range = -1.0:0.01:1.0, startvalue = 0.0),
50+
(label = "D", range = -1:0.01:1.0, startvalue = 0.0)
4551
)
4652

4753
# Connect sliders to observables

0 commit comments

Comments
 (0)