Animation of lines: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
No edit summary |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<html> | <html> | ||
<span onClick="startAnimation1()" style="color:blue">Click here, to start animation | <span onClick="startAnimation1()" style="color:blue">Click here, to start animation</span> | ||
</html> | </html> | ||
<jsxgraph width="600" height="600"> | <jsxgraph width="600" height="600"> | ||
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-10, 10, 10, -10], axis: true | var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-10, 10, 10, -10], axis: true}); | ||
var p0 = brd. | var p0 = brd.create('point', [0,0], {name:'T',trace:true}); | ||
var p1 = brd. | var p1 = brd.create('point', [7, 5], {name:'A',trace:true}); | ||
var p2 = brd. | var p2 = brd.create('point', [5, 7], {name:'B',trace:true}); | ||
var l = brd. | var l = brd.create('line', [p1,p2], {name:''}); | ||
var t = brd. | var t = brd.create('transform', [function(){return p0.X();},function(){return p0.Y();}], {type:'translate'}); | ||
t.bindTo([p1,p2]); | t.bindTo([p1,p2]); // The translation is bound to the points, but the points are not updated, yet | ||
function startAnimation1() { | function startAnimation1() { | ||
p0.moveTo([-5,-8],1500); | p0.moveTo([-5,-8],1500); | ||
} | } | ||
</jsxgraph> | </jsxgraph> | ||
Line 23: | Line 19: | ||
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. | 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. | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-10, 10, 10, -10], axis: true | var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-10, 10, 10, -10], axis: true}); | ||
var p0 = brd. | var p0 = brd.create('point', [0,0], {name:'T',trace:true}); | ||
var p1 = brd. | var p1 = brd.create('point', [7, 5], {name:'A',trace:true}); | ||
var p2 = brd. | var p2 = brd.create('point', [5, 7], {name:'B',trace:true}); | ||
var l = brd. | var l = brd.create('line', [p1,p2], {name:''}); | ||
var t = brd. | var t = brd.create('transform', [function(){return p0.X();},function(){return p0.Y();}], {type:'translate'}); | ||
t.bindTo([p1,p2]); | t.bindTo([p1,p2]); // The translation is bound to the points, but the points are not updated, yet | ||
function startAnimation1() { | function startAnimation1() { | ||
p0.moveTo([-5,-8],1500); | p0.moveTo([-5,-8],1500); | ||
} | } | ||
</source> | </source> | ||
Line 41: | Line 34: | ||
<source lang="html4strict"> | <source lang="html4strict"> | ||
<span onClick="startAnimation1()" style="color:blue">Click here, to start animation 1</span> | <span onClick="startAnimation1()" style="color:blue">Click here, to start animation 1</span> | ||
</source> | </source> | ||
[[Category:Examples]] | [[Category:Examples]] |
Latest revision as of 09:29, 7 June 2011
Click here, to start animation
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});
var p0 = brd.create('point', [0,0], {name:'T',trace:true});
var p1 = brd.create('point', [7, 5], {name:'A',trace:true});
var p2 = brd.create('point', [5, 7], {name:'B',trace:true});
var l = brd.create('line', [p1,p2], {name:''});
var t = brd.create('transform', [function(){return p0.X();},function(){return p0.Y();}], {type:'translate'});
t.bindTo([p1,p2]); // The translation is bound to the points, but the points are not updated, yet
function startAnimation1() {
p0.moveTo([-5,-8],1500);
}
<span onClick="startAnimation1()" style="color:blue">Click here, to start animation 1</span>