Difference between revisions of "Mutually dependent line and gliders"

From JSXGraph Wiki
Jump to navigationJump to search
Line 12: Line 12:
 
var gl1 = board.create('glider', [0,0, el0], {name:'b'});
 
var gl1 = board.create('glider', [0,0, el0], {name:'b'});
 
var gl2 = board.create('glider', [1,0, el1], {name:'a'});
 
var gl2 = board.create('glider', [1,0, el1], {name:'a'});
gl1.draggable = function() {return true; };
+
//gl1.draggable = function() {return true; };
gl2.draggable = function() {return true; };
+
//gl2.draggable = function() {return true; };
  
 
var line = board.create('line', [gl1, gl2]);
 
var line = board.create('line', [gl1, gl2]);
 +
 
var offset = gl2.Y() - gl1.Y();
 
var offset = gl2.Y() - gl1.Y();
  
Line 24: Line 25:
 
     offset = gl2.Y() - gl1.Y();
 
     offset = gl2.Y() - gl1.Y();
 
     });
 
     });
 
 
 
</jsxgraph>
 
</jsxgraph>
  
Line 43: Line 42:
 
var gl1 = board.create('glider', [0,0, el0], {name:'b'});
 
var gl1 = board.create('glider', [0,0, el0], {name:'b'});
 
var gl2 = board.create('glider', [1,0, el1], {name:'a'});
 
var gl2 = board.create('glider', [1,0, el1], {name:'a'});
 +
//gl1.draggable = function() {return true; };
 +
//gl2.draggable = function() {return true; };
 +
 
var line = board.create('line', [gl1, gl2]);
 
var line = board.create('line', [gl1, gl2]);
gl1.draggable = function() {return true; };
 
gl2.draggable = function() {return true; };
 
  
 
var offset = gl2.Y() - gl1.Y();
 
var offset = gl2.Y() - gl1.Y();

Revision as of 09:21, 1 June 2012

The JavaScript code

var board = JXG.JSXGraph.initBoard('jxgbox', {
    boundingbox: [-5,5,5,-5],
    keepaspectratio: true, axis:false, grid:true
    });
board.create('axis',[[0,0],[1,0]], {ticks: {majorHeight:20}});
board.create('axis',[[0,0],[0,1]], {ticks: {majorHeight:20}});

var el0 = board.create('line',[[0,0], [0,1]], {strokeOpacity: .2, strokeColor: '#000000', fixed: true, name: 'x=0'});
var el1 = board.create('line',[[1,0],[1,1]], {strokeOpacity: .2, strokeColor: '#000000', fixed: true, name: 'x=1'});

var gl1 = board.create('glider', [0,0, el0], {name:'b'});
var gl2 = board.create('glider', [1,0, el1], {name:'a'});
//gl1.draggable = function() {return true; };
//gl2.draggable = function() {return true; };

var line = board.create('line', [gl1, gl2]);

var offset = gl2.Y() - gl1.Y();

gl1.on('drag', function() {
    gl2.moveTo([gl1.X(), gl1.Y() + offset]);
    });
gl2.on('drag', function() {
    offset = gl2.Y() - gl1.Y();
    });