<iframe src="http://jsxgraph.uni-bayreuth.de/share/iframe/approximate-pi-pi-with-monte-carlo-method" style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" name="JSXGraph example: Approximate π (Pi) with Monte-Carlo method" allowfullscreen ></iframe>
<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> <div id="resulttext"></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: [-1, 1, 1, -1], axis: true, pan: { needTwoFingers: true } }); var c, i, count = 0, tin = 0, tout = 0, p = [], updateText; var c = board.create('circle', [ [0, 0], 1 ]); p = []; for (var i = 0; i < 50; i++) { p[i] = board.create('point', [function() { return 2 * Math.random() - 1; }, function() { return 2 * Math.random() - 1; }], { name: ' ', withLabel: false }); } updateText = function() { var i, inp, outp, x, y, text = ''; count++; inp = 0; outp = 0; for (i = 0; i < p.length; i++) { x = p[i].X(); y = p[i].Y(); if (x * x + y * y <= 1) { inp++; } else { outp++; } } tin += inp; tout += outp; text += '<b>Current:</b><br />in: ' + inp + ', out: ' + outp + ', total: ' + (inp + outp) + '; ratio: ' + (inp / (inp + outp)) + ', ratio*4: ' + (4 * inp / (inp + outp)) + '.<br /><b>Total:</b> (' + count + ' updates in total)<br/>I´in: ' + tin + ', out: ' + tout + ', total: ' + (tin + tout) + '; <br />ratio: ' + (tin / (tin + tout)) + ', <br />ratio*4: ' + (4 * tin / (tin + tout)); document.getElementById('resulttext').innerHTML = text; } board.on('update', updateText); JXG.addEvent(document.getElementById(BOARDID), 'mousemove', function() { this.update(); }, 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: [-1, 1, 1, -1], axis: true, pan: { needTwoFingers: true } }); var c, i, count = 0, tin = 0, tout = 0, p = [], updateText; var c = board.create('circle', [ [0, 0], 1 ]); p = []; for (var i = 0; i < 50; i++) { p[i] = board.create('point', [function() { return 2 * Math.random() - 1; }, function() { return 2 * Math.random() - 1; }], { name: ' ', withLabel: false }); } updateText = function() { var i, inp, outp, x, y, text = ''; count++; inp = 0; outp = 0; for (i = 0; i < p.length; i++) { x = p[i].X(); y = p[i].Y(); if (x * x + y * y <= 1) { inp++; } else { outp++; } } tin += inp; tout += outp; text += '<b>Current:</b><br />in: ' + inp + ', out: ' + outp + ', total: ' + (inp + outp) + '; ratio: ' + (inp / (inp + outp)) + ', ratio*4: ' + (4 * inp / (inp + outp)) + '.<br /><b>Total:</b> (' + count + ' updates in total)<br/>I´in: ' + tin + ', out: ' + tout + ', total: ' + (tin + tout) + '; <br />ratio: ' + (tin / (tin + tout)) + ', <br />ratio*4: ' + (4 * tin / (tin + tout)); document.getElementById('resulttext').innerHTML = text; } board.on('update', updateText); JXG.addEvent(document.getElementById(BOARDID), 'mousemove', function() { this.update(); }, board);
// Define the id of your board in BOARDID const board = JXG.JSXGraph.initBoard(BOARDID, { boundingbox: [-1, 1, 1, -1], axis: true, pan: { needTwoFingers: true } }); var c, i, count = 0, tin = 0, tout = 0, p = [], updateText; var c = board.create('circle', [ [0, 0], 1 ]); p = []; for (var i = 0; i < 50; i++) { p[i] = board.create('point', [function() { return 2 * Math.random() - 1; }, function() { return 2 * Math.random() - 1; }], { name: ' ', withLabel: false }); } updateText = function() { var i, inp, outp, x, y, text = ''; count++; inp = 0; outp = 0; for (i = 0; i < p.length; i++) { x = p[i].X(); y = p[i].Y(); if (x * x + y * y <= 1) { inp++; } else { outp++; } } tin += inp; tout += outp; text += 'Current:in: ' + inp + ', out: ' + outp + ', total: ' + (inp + outp) + '; ratio: ' + (inp / (inp + outp)) + ', ratio*4: ' + (4 * inp / (inp + outp)) + '.Total: (' + count + ' updates in total)I´in: ' + tin + ', out: ' + tout + ', total: ' + (tin + tout) + '; ratio: ' + (tin / (tin + tout)) + ', ratio*4: ' + (4 * tin / (tin + tout)); document.getElementById('resulttext').innerHTML = text; } board.on('update', updateText); JXG.addEvent(document.getElementById(BOARDID), 'mousemove', function() { this.update(); }, board);
<div id="resulttext"></div>
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.