JSXGraph logo
JSXGraph
JSXGraph share

Share

Function plot animation
QR code
<iframe 
    src="https://www.jsxgraph.org/share/iframe/function-plot-animation" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Function plot animation" 
    allowfullscreen
></iframe>
This code has to
<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-0" class="jxgbox" style="aspect-ratio: 10 / 4; width: 100%;" data-ar="10 / 4"></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';

    // User supplied function to be plotted
    var f = (x) => Math.sin(x);
    
    const board = JXG.JSXGraph.initBoard(BOARDID, {
        boundingbox: [-5, 2, 5, -2],
        axis: true,
        keepaspectratio: false
    });
    
    var start = -4,
        end = 4,
        x = start,
        step = 0.2,
        turtle = board.create('turtle', [x, f(x)]);
    
    var moveForward = function() {
        x += step;
        if (x > end) {
            return;
        }
        turtle.moveTo([x, f(x)]);
        setTimeout(moveForward, 200); // delay by 200 ms
    };
    
    turtle.hideTurtle(); // Hide the turtle arrow
    moveForward(); // Start the drawing
 </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!

// User supplied function to be plotted
var f = (x) => Math.sin(x);

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-5, 2, 5, -2],
    axis: true,
    keepaspectratio: false
});

var start = -4,
    end = 4,
    x = start,
    step = 0.2,
    turtle = board.create('turtle', [x, f(x)]);

var moveForward = function() {
    x += step;
    if (x > end) {
        return;
    }
    turtle.moveTo([x, f(x)]);
    setTimeout(moveForward, 200); // delay by 200 ms
};

turtle.hideTurtle(); // Hide the turtle arrow
moveForward(); // Start the drawing
<jsxgraph width="100%" aspect-ratio="10 / 4" title="Function plot animation" description="This construction was copied from JSXGraph examples database: BTW HERE SHOULD BE A GENERATED LINKuseGlobalJS="false">
   /*
   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.
   */
   
   // User supplied function to be plotted
   var f = (x) => Math.sin(x);
   
   const board = JXG.JSXGraph.initBoard(BOARDID, {
       boundingbox: [-5, 2, 5, -2],
       axis: true,
       keepaspectratio: false
   });
   
   var start = -4,
       end = 4,
       x = start,
       step = 0.2,
       turtle = board.create('turtle', [x, f(x)]);
   
   var moveForward = function() {
       x += step;
       if (x > end) {
           return;
       }
       turtle.moveTo([x, f(x)]);
       setTimeout(moveForward, 200); // delay by 200 ms
   };
   
   turtle.hideTurtle(); // Hide the turtle arrow
   moveForward(); // Start the drawing
</jsxgraph>

Function plot animation

For animated plotting of simple function graphs, the turtle object is useful.
// Define the id of your board in BOARDID

// User supplied function to be plotted
var f = (x) => Math.sin(x);

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-5, 2, 5, -2],
    axis: true,
    keepaspectratio: false
});

var start = -4,
    end = 4,
    x = start,
    step = 0.2,
    turtle = board.create('turtle', [x, f(x)]);

var moveForward = function() {
    x += step;
    if (x > end) {
        return;
    }
    turtle.moveTo([x, f(x)]);
    setTimeout(moveForward, 200); // delay by 200 ms
};

turtle.hideTurtle(); // Hide the turtle arrow
moveForward(); // Start the drawing

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.