JSXGraph logo
JSXGraph
JSXGraph share

Share

Sketching with the sketchcurve element
QR code
<iframe 
    src="https://jsxgraph.uni-bayreuth.de/share/iframe/sketchcurve-element" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Sketching with the sketchcurve element" 
    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: 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';

    const board = JXG.JSXGraph.initBoard(BOARDID, {
        boundingbox: [-10, 10, 10, -10],
        axis: true,
        sketches: {
            enabled: true,
            0: {
                visible: true,
                strokeWidth: 8,
                strokeColor: '#cccccc',
                maxLength: 20,
                deleteOnUp: false,
                lastArrow: { type: 7 }
            },
            1: { strokeWidth: 3 }
        }
    });
    
    board.on('move', function(evt) {
        if (this.isSketching[0]) {
            // Access the first curve by e.g. 
            // console.log(this.sketch.dataX.length);
        }
    });
    
    board.on('up', function(evt) {
        // Access the two curves by e.g. 
        // Finger 1:
        if (this.isSketching[0] && this.sketches[0]) {
            // console.log(this.sketches[0].dataX.length);
        }
        // Finger 2:
        if (this.isSketching[1] && this.sketches[1]) {
            // console.log(this.sketches[1].dataX.length);
        }
    });
    
    var txt = board.create('text', [1, 8, 'Start sketching into the board']);
 </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!

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-10, 10, 10, -10],
    axis: true,
    sketches: {
        enabled: true,
        0: {
            visible: true,
            strokeWidth: 8,
            strokeColor: '#cccccc',
            maxLength: 20,
            deleteOnUp: false,
            lastArrow: { type: 7 }
        },
        1: { strokeWidth: 3 }
    }
});

board.on('move', function(evt) {
    if (this.isSketching[0]) {
        // Access the first curve by e.g. 
        // console.log(this.sketch.dataX.length);
    }
});

board.on('up', function(evt) {
    // Access the two curves by e.g. 
    // Finger 1:
    if (this.isSketching[0] && this.sketches[0]) {
        // console.log(this.sketches[0].dataX.length);
    }
    // Finger 2:
    if (this.isSketching[1] && this.sketches[1]) {
        // console.log(this.sketches[1].dataX.length);
    }
});

var txt = board.create('text', [1, 8, 'Start sketching into the board']);
<jsxgraph width="100%" aspect-ratio="1 / 1" title="Sketching with the sketchcurve element" 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 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 board = JXG.JSXGraph.initBoard(BOARDID, {
       boundingbox: [-10, 10, 10, -10],
       axis: true,
       sketches: {
           enabled: true,
           0: {
               visible: true,
               strokeWidth: 8,
               strokeColor: '#cccccc',
               maxLength: 20,
               deleteOnUp: false,
               lastArrow: { type: 7 }
           },
           1: { strokeWidth: 3 }
       }
   });
   
   board.on('move', function(evt) {
       if (this.isSketching[0]) {
           // Access the first curve by e.g. 
           // console.log(this.sketch.dataX.length);
       }
   });
   
   board.on('up', function(evt) {
       // Access the two curves by e.g. 
       // Finger 1:
       if (this.isSketching[0] && this.sketches[0]) {
           // console.log(this.sketches[0].dataX.length);
       }
       // Finger 2:
       if (this.isSketching[1] && this.sketches[1]) {
           // console.log(this.sketches[1].dataX.length);
       }
   });
   
   var txt = board.create('text', [1, 8, 'Start sketching into the board']);
</jsxgraph>

Sketching with the sketchcurve element

A basic example of using the `sketchcurve` element of the board. Here, it may be used as a visual element if a JSXGraph applet is displayed on a projector.
// Define the id of your board in BOARDID

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-10, 10, 10, -10],
    axis: true,
    sketches: {
        enabled: true,
        0: {
            visible: true,
            strokeWidth: 8,
            strokeColor: '#cccccc',
            maxLength: 20,
            deleteOnUp: false,
            lastArrow: { type: 7 }
        },
        1: { strokeWidth: 3 }
    }
});

board.on('move', function(evt) {
    if (this.isSketching[0]) {
        // Access the first curve by e.g. 
        // console.log(this.sketch.dataX.length);
    }
});

board.on('up', function(evt) {
    // Access the two curves by e.g. 
    // Finger 1:
    if (this.isSketching[0] && this.sketches[0]) {
        // console.log(this.sketches[0].dataX.length);
    }
    // Finger 2:
    if (this.isSketching[1] && this.sketches[1]) {
        // console.log(this.sketches[1].dataX.length);
    }
});

var txt = board.create('text', [1, 8, 'Start sketching into the board']);

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.