Toggle show / drag properties in script

I’m wondering if there’s any way to change whether a point on a graph is draggable from within a script. For example, to “lock in” a draggable point when a student presses a button or chooses a certain answer in a checklist.

It would also be nice to be able to toggle whether something in the expression list is shown or hidden, or turn on/off the animations that you set in the expression list.

I don’t see sinks listed for this in the documentation so maybe it’s not currently implemented. If anyone has an idea for a workaround that would be cool.

Expressions are easy to toggle. Just have a variable that will change based on your button press. Then, use that as a restriction, just as you would restrict domain for a function.

For example, in graph CL:

number("p"): numericValue("\mod(${p},2)")

In graph, this function would start displayed, then toggle on/off with the button press.

f(x)=3x+5 {p=0}

Ok thank you, that’s very helpful!

Do you have any suggestions for the dragging thing? You can make a point draggable using 2 numbers with sliders, and then set those numbers in the script as well to prevent the dragging. But a “when” always needs an “otherwise” so is there a way to only set a value for a number when a certain condition is met, and otherwise let it be defined by the slider (that the students can’t see)?

Just did a quick search. The work around for points is to use sliders for the coordinates (say (x_P,y_P) ), as well as for the bounds of the slider (e.g. (x_1<=x_P<=x_2)). Then, capture the coordinates when the button press and set the upper and lower bounds of the slider to those values.

In button CL, for :

capture("x_P"): graph.number("x_P")
capture("y_P): graph.number("_P")

In graph CL (similar for y):

number("x_1"): when button.pressCount>0 button.lastValue("x_P")
                         otherwise -10 #or whatever you want
number("x_2"): when button.pressCount>0 button.lastValue("x_P")
                         otherwise 10

You could reenable draggability with more conditions.

You can also put restrictions next to a coordinate as you would with a function, but it will lock that number (unless it’s a function linked to the other coordinate’s slider).

A=(x_1,y_1 {p=0}) can be dragged left to right and toggled as with the function, but y_1 would be locked.

This is great, thanks! I didn’t know you could set slider bounds to variables but that’s good to know in general too.

I just tried what you said in your other reply and ran into the same thing. I wish that we just had sinks for these things, it would be a lot easier.