JSXGraph logo
JSXGraph
JSXGraph share

Share

Animation of lines
QR code
<iframe 
    src="https://www.jsxgraph.org/share/iframe/animation-of-lines" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Animation of lines" 
    allowfullscreen
></iframe>
This code has to
<span onClick="startAnimation()">Click here, to start animation</span>
<br>
<span onClick="reset()">Reset</span>

<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-0" class="jxgbox" style="aspect-ratio: 1 / 1; width: 100%;" data-ar="1 / 1"></div>
</div>

<script type = "text/javascript"> 
    /*
    This example is licensed under a 
    Creative Commons Attribution 4.0 International License.
    https://creativecommons.org/licenses/by/4.0/
    
    Please note you have to mention 
    The Center of Mobile Learning with Digital Technology
    in the credits.
    */
    
    const BOARDID = 'board-0';

    const board = JXG.JSXGraph.initBoard(BOARDID, {
        boundingbox: [-10, 10, 10, -10],
        axis: true
    });
    var p0 = board.create('point', [0, 0], {
        name: 'T',
        trace: true
    });
    var p1 = board.create('point', [7, 5], {
        name: 'A',
        trace: true
    });
    var p2 = board.create('point', [5, 7], {
        name: 'B',
        trace: true
    });
    var l = board.create('line', [p1, p2], {
        name: ''
    });
    
    var t = board.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 startAnimation() {
        p0.moveTo([-5, -8], 1500);
    }
    
    function reset() {
        p0.moveTo([0, 0]);
        p0.clearTrace();
        p1.clearTrace();
        p2.clearTrace();
    }
 </script> 
/*
This example is licensed under a 
Creative Commons Attribution 4.0 International License.
https://creativecommons.org/licenses/by/4.0/

Please note you have to mention 
The Center of Mobile Learning with Digital Technology
in the credits.
*/

const BOARDID = 'your_div_id'; // Insert your id here!

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-10, 10, 10, -10],
    axis: true
});
var p0 = board.create('point', [0, 0], {
    name: 'T',
    trace: true
});
var p1 = board.create('point', [7, 5], {
    name: 'A',
    trace: true
});
var p2 = board.create('point', [5, 7], {
    name: 'B',
    trace: true
});
var l = board.create('line', [p1, p2], {
    name: ''
});

var t = board.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 startAnimation() {
    p0.moveTo([-5, -8], 1500);
}

function reset() {
    p0.moveTo([0, 0]);
    p0.clearTrace();
    p1.clearTrace();
    p2.clearTrace();
}

Animation of lines

The point $T$ controls the movement of the line. The coordinates of $T$ define a transformation (translation). This transformation is applied to the points $A$ and $B$. which in turn define the line to be animated. Of course, in applications $T$ should be hidden.
Click here, to start animation
Reset
<span onClick="startAnimation()">Click here, to start animation</span>
<br>
<span onClick="reset()">Reset</span>
// Define the id of your board in BOARDID

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-10, 10, 10, -10],
    axis: true
});
var p0 = board.create('point', [0, 0], {
    name: 'T',
    trace: true
});
var p1 = board.create('point', [7, 5], {
    name: 'A',
    trace: true
});
var p2 = board.create('point', [5, 7], {
    name: 'B',
    trace: true
});
var l = board.create('line', [p1, p2], {
    name: ''
});

var t = board.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 startAnimation() {
    p0.moveTo([-5, -8], 1500);
}

function reset() {
    p0.moveTo([0, 0]);
    p0.clearTrace();
    p1.clearTrace();
    p2.clearTrace();
}

license

This example is licensed under a Creative Commons Attribution 4.0 International License.
Please note you have to mention The Center of Mobile Learning with Digital Technology in the credits.