JSXGraph logo
JSXGraph
JSXGraph share

Share

BROKEN | Programming turtle graphics
QR code
<iframe 
    src="http://jsxgraph.uni-bayreuth.de/share/iframe/programming-turtle-graphics" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: BROKEN | Programming turtle graphics" 
    allowfullscreen
></iframe>
This code has to
<textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">t.fd(100);

<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>


<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>
<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);
        document.getElementById('logwindow').innerHTML += code + '\n';
        //document.getElementById('inputtext').value = '';
        board.unsuspendUpdate();
    }
    
    function clearturtle() {
        t.cs();
        //document.getElementById('inputtext').value = 't.fd(100);';
    }
    
    function clearlog() {
        document.getElementById('logwindow').innerHTML = '';
    }
 </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);
    document.getElementById('logwindow').innerHTML += code + '\n';
    //document.getElementById('inputtext').value = '';
    board.unsuspendUpdate();
}

function clearturtle() {
    t.cs();
    //document.getElementById('inputtext').value = 't.fd(100);';
}

function clearlog() {
    document.getElementById('logwindow').innerHTML = '';
}

BROKEN | Programming turtle graphics

### List of available commands There is a predefined turtle object *t*. Therefore, all commands start with *t*, like *t.fd(100)*; * t.forward(len); or t.fd(len); * t.back(len); or t.bk(len); * t.right(angle); or t.rt(angle); *) * t.left(angle); or t.lt(angle); *) * t.penUp(); or t.pu(); * t.penDown(); or t.pd(); * t.clearScreen(); or t.cs(); * t.clean(); * t.setPos(x,y); * t.home(); * t.hideTurtle(); or t.ht(); * t.showTurtle(); or t.st(); * t.setPenSize(size); (size: number) * t.setPenColor(col); (col: colorString, e.g. 'red' or '#ff0000') * t.setAttribute({key1:value1,key2:value2,...}); * t.pushTurtle() * t.popTurtle() * t.lookTo(dir) or t.lookTo([x,y]) (Turtle looks to a coordinate pair. If t2 is another turtle object: t.lookTo(t2.pos)) * t.moveTo([x,y]) (Turtle goes forward to the coordinates pair. The turtles direction is not changed.) * t.X(), t.Y(): get the position of the turtle t.
<textarea id="inputtext" rows=5 cols=35 wrap="off" style="width:600px;">t.fd(100);
// 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);
    document.getElementById('logwindow').innerHTML += code + '\n';
    //document.getElementById('inputtext').value = '';
    board.unsuspendUpdate();
}

function clearturtle() {
    t.cs();
    //document.getElementById('inputtext').value = 't.fd(100);';
}

function clearlog() {
    document.getElementById('logwindow').innerHTML = '';
}
<pre id="logwindow" class="javascript javascript" style="font-family:monospace;"></pre>

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.