Pause and Play button in interactive sage demos

53 views
Skip to first unread message

Gaurish Telang

unread,
Aug 21, 2022, 3:58:28 AM8/21/22
to sage-support
 I am studying Lissajous curves with the following code, that works as expected.

```
import numpy as np

tmin = -30*np.pi
tmax = 30*np.pi

@interact
def _(a    = slider(np.linspace(-1,1,100),default=0.39),
      b    = slider(np.linspace(-1,1,100),default=0.49),
      delta= slider(np.linspace(-1,1,100),default=-1),
      tt=slider(tmin,tmax,default=0,step_size=0.001,label="t"),
      trace=checkbox(default=False,label="Trace")):
   
    t=var('t')
    p=parametric_plot( (sin(a*t+delta), sin(b*t)), (t, tmin, tmax),
                      plot_points  = 4000,
                      aspect_ratio = 1,
                      gridlines    = 'major',figsize=5)
    if trace:
         p += point((sin(a*tt+delta),sin(b*tt)), color="red", size=100)
    show(p)
```

ksnip_20220821-131727.png

However, I would like to have a "PLAY" button so that I can see the  position of the point gets updated by incrementing the value of `t` automatically. It would be nice to have a "PAUSE" button as well.

How can I do that? 

kcrisman

unread,
Aug 22, 2022, 9:05:33 AM8/22/22
to sage-support
This is a great question, but I don't think it's currently supported.  However, there appears to be a Jupyter widget which supports this:


so in principle we could add that to the Jupyter implementation of @interact.  I'm not sure whether William or Andrey would know/want to do that on CoCalc sagews/Sage cell server, respectively.

Kwankyu

unread,
Aug 23, 2022, 9:40:59 PM8/23/22
to sage-support
Animated plots may help you:


For play button, you may use interactive(). For example,

x = SR.var("x")
sines = [plot(c*sin(x), (-2*pi,2*pi), color=Color(c,0,0), ymin=-1, ymax=1) for c in range(0,1,.2)]
a = animate(sines)
a.interactive()

It is unfortunate this interactive animated plot is rendered in 3d, though.



Reply all
Reply to author
Forward
0 new messages