Random points: Difference between revisions
From JSXGraph Wiki
No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 14: | Line 14: | ||
board.suspendUpdate(); | board.suspendUpdate(); | ||
for (var i=0;i<50;i++) { | for (var i=0;i<50;i++) { | ||
var p = board. | var p = board.create('point', | ||
[Math.random(),Math.random()],{size:3,withLabel:false}); | [Math.random(),Math.random()],{size:3,withLabel:false}); | ||
} | } | ||
Line 31: | Line 31: | ||
board.suspendUpdate(); | board.suspendUpdate(); | ||
for (var i=0;i<50;i++) { | for (var i=0;i<50;i++) { | ||
var p = board. | var p = board.create('point', | ||
[Math.random(),Math.random()],{size:3,withLabel:false}); | [Math.random(),Math.random()],{size:3,withLabel:false}); | ||
} | } | ||
Line 49: | Line 49: | ||
board2.suspendUpdate(); | board2.suspendUpdate(); | ||
for (var i=0;i<50;i++) { | for (var i=0;i<50;i++) { | ||
var p2 = board2. | var p2 = board2.create('point', [function(){return Math.random();},function(){ return Math.random()}], {size:3, withLabel: false}); | ||
} | } | ||
board2.unsuspendUpdate(); | board2.unsuspendUpdate(); | ||
Line 56: | Line 56: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
board2 = JXG.JSXGraph.initBoard(' | board2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-0.02, 1.02, 1.02, -0.02]}); | ||
board2.suspendUpdate(); | board2.suspendUpdate(); | ||
for (var i=0;i<50;i++) { | for (var i=0;i<50;i++) { | ||
var p2 = board2. | var p2 = board2.create('point', [function(){return Math.random();},function(){ return Math.random()}], {size:3, withLabel: false}); | ||
} | } | ||
board2.unsuspendUpdate(); | board2.unsuspendUpdate(); |
Latest revision as of 08:19, 3 March 2021
Draw 50 random points - version 1
In the first version each point receives random coordinates once at construction time.
board = JXG.JSXGraph.initBoard('box', {boundingbox: [-0.02, 1.02, 1.02, -0.02]});
function reload() {
JXG.JSXGraph.freeBoard(board);
board = JXG.JSXGraph.initBoard('box', {boundingbox: [-0.02, 1.02, 1.02, -0.02]});
board.suspendUpdate();
for (var i=0;i<50;i++) {
var p = board.create('point',
[Math.random(),Math.random()],{size:3,withLabel:false});
}
board.unsuspendUpdate();
}
reload();
Draw 50 random points - version 2
Here, at construction time each point receives a function pair as coordinates. In each update these functions which return Math.random() are called. Thus in each update each point receives new random coordinates. The 50 points are updated on the onmousemove event.
Please, move the mouse pointer over this area:
board2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-0.02, 1.02, 1.02, -0.02]});
board2.suspendUpdate();
for (var i=0;i<50;i++) {
var p2 = board2.create('point', [function(){return Math.random();},function(){ return Math.random()}], {size:3, withLabel: false});
}
board2.unsuspendUpdate();
JXG.addEvent(document.getElementById('box2'), 'mousemove', function () { this.update(); }, board2);