Animation of lines: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 5: | Line 5: | ||
<jsxgraph width="600" height="600"> | <jsxgraph width="600" height="600"> | ||
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-10, 10, 10, -10], axis: true, grid: false}); | var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-10, 10, 10, -10], axis: true, grid: false}); | ||
var p0 = brd.createElement('point', [0, | var p0 = brd.createElement('point', [0,0], {name:'T',trace:true}); | ||
var p1 = brd.createElement('point', [ | var p1 = brd.createElement('point', [7, 5], {name:'A',trace:true}); | ||
var p2 = brd.createElement('point', [5, | var p2 = brd.createElement('point', [5, 7], {name:'B',trace:true}); | ||
var l = brd.createElement('line', [p1,p2], {name:''}); | var l = brd.createElement('line', [p1,p2], {name:''}); | ||
var t = brd.createElement('transform', [function(){return p0.X();},function(){return p0.Y();}], {type:'translate'}); | var t = brd.createElement('transform', [function(){return p0.X();},function(){return p0.Y();}], {type:'translate'}); |
Revision as of 15:56, 18 December 2009
Click here, to start animation 1 Click here, to start animation 2
The JavaScript code
The point "p0" controls the movement of the line. The coordinates of p0 define a transformation (translation). This transformation is applied to the points p1 and p2. Of course, p0 should be hidden.
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-10, 10, 10, -10], axis: true, grid: false});
var p0 = brd.createElement('point', [0,0], {name:'T',trace:true});
var p1 = brd.createElement('point', [7, 5], {name:'A',trace:true});
var p2 = brd.createElement('point', [5, 7], {name:'B',trace:true});
var l = brd.createElement('line', [p1,p2], {name:''});
var t = brd.createElement('transform', [function(){return p0.X();},function(){return p0.Y();}], {type:'translate'});
t.bindTo([p1,p2]);
function startAnimation1() {
p0.moveTo([-5,-8],1500);
}
function startAnimation2() {
p0.moveTo([0,0],1500);
}
<span onClick="startAnimation1()" style="color:blue">Click here, to start animation 1</span>
<span onClick="startAnimation2()" style="color:red">Click here, to start animation 2</span>