JSXGraph logo
JSXGraph
JSXGraph share

Share

n-gons
QR code
<iframe 
    src="http://jsxgraph.uni-bayreuth.de/share/iframe/n-gones" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: n-gons" 
    allowfullscreen
></iframe>
This code has to
<textarea id="inputtext" rows=4 cols=35 wrap="off" style="width:600px;">
t.cs();
t.setProperty({strokeWidth:4,strokeOpacity:0.6,fillOpacity:0.3});
t.hideTurtle();
mn_gon(36, 20);
</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', [], { fillColor: 'yellow', highlight: false });
    
    var n_gon = function(ne, sz) {
        var i;
        for (i = 0; i < ne; i++) {
            t.rt(360 / ne);
            t.fd(sz);
        }
    };
    
    var mn_gon = function(ne, sz) {
        var i;
        for (i = 0; i < ne; i++) {
            t.rt(360 / ne);
            n_gon(ne, sz);
        }
    };
    
    function run() {
        var code = document.getElementById('inputtext').value;
        if (code == '') { return; }
        eval(code);
    }
    
    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', [], { fillColor: 'yellow', highlight: false });

var n_gon = function(ne, sz) {
    var i;
    for (i = 0; i < ne; i++) {
        t.rt(360 / ne);
        t.fd(sz);
    }
};

var mn_gon = function(ne, sz) {
    var i;
    for (i = 0; i < ne; i++) {
        t.rt(360 / ne);
        n_gon(ne, sz);
    }
};

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

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

n-gons

This interactive turtle graphics example lets users draw regular polygons with $n$ vertices ($n$-gons) and nested shapes. It features a text area for code input, where the code can be changed online, and buttons to run or clear the drawing dynamically. The default `mn_gon(36, 20);` is to draw $36$ $36$-gons, each having edge size 20.
<textarea id="inputtext" rows=4 cols=35 wrap="off" style="width:600px;">
t.cs();
t.setProperty({strokeWidth:4,strokeOpacity:0.6,fillOpacity:0.3});
t.hideTurtle();
mn_gon(36, 20);
</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', [], { fillColor: 'yellow', highlight: false });

var n_gon = function(ne, sz) {
    var i;
    for (i = 0; i < ne; i++) {
        t.rt(360 / ne);
        t.fd(sz);
    }
};

var mn_gon = function(ne, sz) {
    var i;
    for (i = 0; i < ne; i++) {
        t.rt(360 / ne);
        n_gon(ne, sz);
    }
};

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

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.