Dependent gliders: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
(12 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
var P1 = brd.create('point', [4,-1], {name:'', face:'[]'}); | var P1 = brd.create('point', [4,-1], {name:'', face:'[]'}); | ||
var li = brd.create('line', [P0,P1]); | var li = brd.create('line', [P0,P1]); | ||
var A = brd.create('glider', [0,-1,li]); | var A = brd.create('glider', [0,-1,li], {name:'A'}); | ||
var B = brd.create('glider', [-3,-1,li]); | var B = brd.create('glider', [-3,-1,li], {name:'B'}); | ||
var C = brd.create('glider', [ 3,-1,li]); | var C = brd.create('glider', [ 3,-1,li], {name:'C'}); | ||
brd. | |||
brd.on('update', function() { | |||
var o; | var o; | ||
if (typeof brd.touches != 'undefined' && brd.touches.length>0) { | if (typeof brd.touches != 'undefined' && brd.touches.length>0) { | ||
Line 16: | Line 17: | ||
return; | return; | ||
} | } | ||
if (o==A) { | if (o==A) { | ||
B.position = A.position - 0.3; | B.position = A.position - 0.3; | ||
B.prepareUpdate().update(true).updateRenderer(); | B.prepareUpdate().update(true).updateRenderer(); | ||
C.setPositionDirectly(JXG.COORDS_BY_USER, A.X()+3, C.Y()); | C.setPositionDirectly(JXG.COORDS_BY_USER, [A.X()+3, C.Y()]); | ||
C.prepareUpdate().update().updateRenderer(); | C.prepareUpdate().update().updateRenderer(); | ||
} else if (o==B) { | } else if (o==B) { | ||
Line 27: | Line 28: | ||
A.prepareUpdate().update(true).updateRenderer(); | A.prepareUpdate().update(true).updateRenderer(); | ||
C.setPositionDirectly(JXG.COORDS_BY_USER, A.X()+3, C.Y()); | C.setPositionDirectly(JXG.COORDS_BY_USER, [A.X()+3, C.Y()]); | ||
C.prepareUpdate().update().updateRenderer(); | C.prepareUpdate().update().updateRenderer(); | ||
} else if (o==C) { | } else if (o==C) { | ||
A.setPositionDirectly(JXG.COORDS_BY_USER, C.X()-3, A.Y()); | A.setPositionDirectly(JXG.COORDS_BY_USER, [C.X()-3, A.Y()]); | ||
A.prepareUpdate().update().updateRenderer(); | A.prepareUpdate().update().updateRenderer(); | ||
Line 36: | Line 37: | ||
B.prepareUpdate().update(true).updateRenderer(); | B.prepareUpdate().update(true).updateRenderer(); | ||
} | } | ||
} | }); | ||
</jsxgraph> | </jsxgraph> | ||
Line 45: | Line 46: | ||
var P1 = brd.create('point', [4,-1], {name:'', face:'[]'}); | var P1 = brd.create('point', [4,-1], {name:'', face:'[]'}); | ||
var li = brd.create('line', [P0,P1]); | var li = brd.create('line', [P0,P1]); | ||
var A = brd.create('glider', [0,-1,li]); | var A = brd.create('glider', [0,-1,li], {name:'A'}); | ||
var B = brd.create('glider', [-3,-1,li]); | var B = brd.create('glider', [-3,-1,li], {name:'B'}); | ||
var C = brd.create('glider', [ 3,-1,li]); | var C = brd.create('glider', [ 3,-1,li], {name:'C'}); | ||
brd. | |||
brd.on('update', function() { | |||
var o; | var o; | ||
if (typeof brd.touches != 'undefined' && brd.touches.length>0) { | if (typeof brd.touches != 'undefined' && brd.touches.length>0) { | ||
Line 58: | Line 59: | ||
return; | return; | ||
} | } | ||
if (o==A) { | if (o==A) { | ||
B.position = A.position - 0.3; | B.position = A.position - 0.3; | ||
B.prepareUpdate().update(true).updateRenderer(); | B.prepareUpdate().update(true).updateRenderer(); | ||
C.setPositionDirectly(JXG.COORDS_BY_USER, [A.X()+3, C.Y()]); | |||
C.setPositionDirectly(JXG.COORDS_BY_USER, A.X()+3, C.Y()); | |||
C.prepareUpdate().update().updateRenderer(); | C.prepareUpdate().update().updateRenderer(); | ||
} else if (o==B) { | } else if (o==B) { | ||
A.position = B.position + 0.3; | A.position = B.position + 0.3; | ||
A.prepareUpdate().update(true).updateRenderer(); | A.prepareUpdate().update(true).updateRenderer(); | ||
C.setPositionDirectly(JXG.COORDS_BY_USER, A.X()+3, C.Y()); | C.setPositionDirectly(JXG.COORDS_BY_USER, [A.X()+3, C.Y()]); | ||
C.prepareUpdate().update().updateRenderer(); | C.prepareUpdate().update().updateRenderer(); | ||
} else if (o==C) { | } else if (o==C) { | ||
A.setPositionDirectly(JXG.COORDS_BY_USER, C.X()-3, A.Y()); | A.setPositionDirectly(JXG.COORDS_BY_USER, [C.X()-3, A.Y()]); | ||
A.prepareUpdate().update().updateRenderer(); | A.prepareUpdate().update().updateRenderer(); | ||
Line 81: | Line 79: | ||
B.prepareUpdate().update(true).updateRenderer(); | B.prepareUpdate().update(true).updateRenderer(); | ||
} | } | ||
} | }); | ||
</source> | </source> | ||
[[Category:Examples]] | [[Category:Examples]] |
Latest revision as of 09:35, 18 June 2013
The underlying JavaScript code
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-5,5,5,-5], axis:true});
var P0 = brd.create('point', [-4,-1], {name:'', face:'[]'});
var P1 = brd.create('point', [4,-1], {name:'', face:'[]'});
var li = brd.create('line', [P0,P1]);
var A = brd.create('glider', [0,-1,li], {name:'A'});
var B = brd.create('glider', [-3,-1,li], {name:'B'});
var C = brd.create('glider', [ 3,-1,li], {name:'C'});
brd.on('update', function() {
var o;
if (typeof brd.touches != 'undefined' && brd.touches.length>0) {
o = brd.touches[0].obj;
} else if (brd.mouse!=null && typeof brd.mouse.obj != 'undefined') {
o = brd.mouse.obj;
} else {
return;
}
if (o==A) {
B.position = A.position - 0.3;
B.prepareUpdate().update(true).updateRenderer();
C.setPositionDirectly(JXG.COORDS_BY_USER, [A.X()+3, C.Y()]);
C.prepareUpdate().update().updateRenderer();
} else if (o==B) {
A.position = B.position + 0.3;
A.prepareUpdate().update(true).updateRenderer();
C.setPositionDirectly(JXG.COORDS_BY_USER, [A.X()+3, C.Y()]);
C.prepareUpdate().update().updateRenderer();
} else if (o==C) {
A.setPositionDirectly(JXG.COORDS_BY_USER, [C.X()-3, A.Y()]);
A.prepareUpdate().update().updateRenderer();
B.position = A.position - 0.3;
B.prepareUpdate().update(true).updateRenderer();
}
});