API options for slider to play only forward?

257 views
Skip to first unread message

Andrew Dawes

unread,
Feb 12, 2018, 7:52:01 PM2/12/18
to desmos-api-discuss
I am thrilled to have found desmos API and I'm working on some self-guided lessons for physics courses. I wonder if there is a way to set a slider to only play forward (with repeat is ok) as opposed to default "bounce" at the end of range?

I have students explore time-evolution so it's confusing for the "time" to reverse at the end of a simulation.

Thanks!

Andy

Jason Merrill

unread,
Feb 12, 2018, 8:03:02 PM2/12/18
to desmos-api-discuss
Glad to hear that the API has been useful for your lessons.

The flag for setting slider loop mode is not currently exposed through the public API. We may expose this option in a future version, but one workaround you could use in the meantime is to

1. Create a graph in the calculator with a slider that you want, and set it playing
2. Use the slider loop mode UI in the upper right of the expression to change the loop mode.
3. Use calculator.getState() to get the calculator's state, and save this somewhere
4. Use calculator.setState() with this saved state.

I've found that it's often easiest to only use setExpression for the parts of a graph that are truly dynamic and depend on information from the outside world. For anything that you can author once using the calculator, it's generally a lot easier to build things that way than to use a large number of calls to setExpression.

Andrew Dawes

unread,
Feb 12, 2018, 8:51:40 PM2/12/18
to desmos-api-discuss
Ok, I'll give that a shot, thanks!

Robert Niemeyer

unread,
Apr 14, 2021, 2:58:02 PM4/14/21
to desmos-api-discuss
Hello!

I am not sure what I'm doing wrong, exactly. I'm fairly new to JavaScript, but I've picked it up quite quickly.  I am attempting to do something similar: play an animation by clicking a button on my webpage. I have a div containing some graphics and the Desmos Graphing Calculator.  I've programmed everything to be set up so that right now if a student clicked on play, it would show shading the region under a graph. Great! That works! But I want to be able to time the playing with a narration and not have to require the student to push play.  I would like to be able to toggle the playing of the animation as needed AND also give the student a button to click if they so choose.

I've copied the result of 'getState()' for the calculator from the console: 

{
    "type": "expression",
    "id": "slider1",
    "color": "#6042a6",
    "latex": "a=3",
    "slider": {
        "hardMin": true,
        "hardMax": true,
        "isPlaying": true,
        "min": "-2",
        "max": "3",
        "step": "1"
    }
}

Now, I'm assuming I would remove the quotation marks from _type_, _id_, etc.  I also assume that "isPlaying: true" should toggle the state of the slider: playing or not.  But this does not work when copied into my script.  The graph is still static until play is pressed, which is not desired.  

Can you please help?

Robert Niemeyer

unread,
Apr 14, 2021, 2:58:05 PM4/14/21
to desmos-api-discuss
Actually, never mind. I figured out how to implement your suggestion.  I needed to store everything I copied into my previous message in a variable, e.g., myState and then run the command calculator.setState(myState); in my JS file. 

Of course, I still need to figure out now how to trigger the playing at a specific time and make a button, but that may be a pure JS issue and not a Desmos API issue.

If you have any insight/suggestions on my existing problem, I'd like to hear them. Thank you.



On Monday, February 12, 2018 at 6:51:40 PM UTC-7 andrew...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages