Turn a point's visibility on and off dynamically

66 views
Skip to first unread message

Marcelo Rodrigues

unread,
Nov 30, 2023, 4:37:00 AM11/30/23
to JSXGraph
Hello everybody,

Please, I would like to ask for help on the following question:

1- Define a random variable in Moodle -> w = shuffle([0,1]);

2- Define the point in jsxgraph: 

var interof1 = b.create('intersection', [l1, l6, 0],{name:'O2', size:3,fixed:true, Color:'#ff0000', visible:{ if w[0]==0, true, false}});

3- My objective is that if w[0]==0 the point "interof1" is visible and if w[0]==1 the point is not visible.

4- I tried to apply the code to the visible property: visible:{if w[0]==0, true,
    false}}); - but it did not work.

5- Is there any way to do this?

Thank you very much, Marcelo.

古今中外数学网

unread,
Nov 30, 2023, 4:44:42 AM11/30/23
to JSXGraph
I am a old style one, so not sure your code style.

but it should work, if you put code as below:

visible: function(){return (w[0]==0?true:false)}

Marcelo Rodrigues

unread,
Nov 30, 2023, 5:37:54 AM11/30/23
to JSXGraph
Hello,

Thank you very much for your feedback and explanations! Thank you very much!

I created a new point as below:

var p100 = b.create('point',[20,20],{size:4, visible: function(){return (w[0]==0?true:false)}});

and I applied the function you sent me.

However, the point is always visible, even if w[0] varies between 0 and 1.

The p100 point visibility turn-off did not work.

I'm checking to see if I made a mistake...

Marcelo.

古今中外数学网

unread,
Nov 30, 2023, 5:48:57 AM11/30/23
to JSXGraph
you may need add board.update(); as last line in your code, to update board.

Marcelo Rodrigues

unread,
Nov 30, 2023, 6:13:19 AM11/30/23
to JSXGraph
Hello,

Thank you very much for your feedback!

I put the code you sent me, but it didn't work.

The created point "p100" always remains visible, even with w[0] varying between 0 and 1.

Marcelo.

Alfred Wassermann

unread,
Nov 30, 2023, 8:21:01 AM11/30/23
to JSXGraph
Dear all,
here is an example which uses two types of random variables. w[0] is randomly set on load, w[1] is set to random value at every update.

-----------------------
const board = JXG.JSXGraph.initBoard('jxgbox', {
    boundingbox: [-5, 5, 5, -5], axis:true
});

var w = [0, 0];

var p0 = board.create('point', [2, -3], {name:'drag me', color:'blue'});

// Static version:
// Set w[0] once:
w[0] = Math.round(Math.random());
// Create the point with fixed visibility
var p100 = board.create('point',[2,2], {
    size:4,
    visible: w[0]==0?true:false
});

// Dynamic version:
// Set w[0] once:
w[1] = function() { return (Math.round(Math.random())==0?true:false); };
// Create the point with fixed visibility
var p200 = board.create('point',[2,-2], {
    size:4,
    visible: w[1]
});
-----------------------

See it live at https://jsfiddle.net/v1n20w3c/. In your case, it might be helpful to print the value of w[0] to the console, i.e.
     console.log(w[0]);
to see what it contains.

Best wishes,
Alfred

Marcelo Rodrigues

unread,
Dec 1, 2023, 12:22:48 PM12/1/23
to jsxg...@googlegroups.com
Dear Alfred,

Thank you very much for your support and help!

I am analyzing the behavior of the programming you made, as I want to use it in an exercise for students in the Moodle environment.

I was in doubt, after the students answered the quiz, if the answer they originally gave would remain the same or if it would "change" each time the question was accessed.

Thank you very much! Marcelo.

Não contém vírus.www.avg.com

--
You received this message because you are subscribed to a topic in the Google Groups "JSXGraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsxgraph/vMWAPWb5Xg4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsxgraph+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsxgraph/31f0af5d-d5de-4d5e-afb0-ccda3571a40cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages