JSXGraph logo
JSXGraph
JSXGraph share

Share

Turtle spiral
QR code
<iframe 
    src="https://jsxgraph.uni-bayreuth.de/share/iframe/turtle-spiral" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Turtle spiral" 
    allowfullscreen
></iframe>
This code has to
<textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">for (var i=0;i<100;i++){
 t.forward(i*3);
 t.left(71);
}
</textarea>
<input type="button" value="run" onClick="run()">
<input type="button" value="clear" onClick="clearturtle()">

<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 ShareAlike 4.0 International License.
    https://creativecommons.org/licenses/by-sa/4.0/
    
    Please note you have to mention 
    The Center of Mobile Learning with Digital Technology
    in the credits.
    */
    
    const BOARDID = 'board-0';

    var board = JXG.JSXGraph.initBoard(BOARDID, { boundingbox: [-300, 300, 300, -300], keepaspectratio: true });
    var t = board.create('turtle');
    
    function run() {
        board.suspendUpdate();
        var code = document.getElementById('inputtext').value;
        if (code == '') { return; }
        eval(code);
        board.unsuspendUpdate();
    }
    
    function clearturtle() {
        t.cs();
    }
    run();
 </script> 
/*
This example is licensed under a 
Creative Commons Attribution ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-sa/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!

var board = JXG.JSXGraph.initBoard(BOARDID, { boundingbox: [-300, 300, 300, -300], keepaspectratio: true });
var t = board.create('turtle');

function run() {
    board.suspendUpdate();
    var code = document.getElementById('inputtext').value;
    if (code == '') { return; }
    eval(code);
    board.unsuspendUpdate();
}

function clearturtle() {
    t.cs();
}
run();

Turtle spiral

This code sets up a JSXGraph board with a turtle that executes user-provided commands from a text area. The `run()` function evaluates the input, while `clearturtle()` stops the active timer and resets the turtle, enabling interactive drawing and animations. **AI generated desctiption**
<textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">for (var i=0;i<100;i++){
 t.forward(i*3);
 t.left(71);
}
</textarea>
<input type="button" value="run" onClick="run()">
<input type="button" value="clear" onClick="clearturtle()">
// Define the id of your board in BOARDID

var board = JXG.JSXGraph.initBoard(BOARDID, { boundingbox: [-300, 300, 300, -300], keepaspectratio: true });
var t = board.create('turtle');

function run() {
    board.suspendUpdate();
    var code = document.getElementById('inputtext').value;
    if (code == '') { return; }
    eval(code);
    board.unsuspendUpdate();
}

function clearturtle() {
    t.cs();
}
run();

license

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