Random points

From JSXGraph Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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() {
    board = JXG.JSXGraph.initBoard('box', {boundingbox: [-0.02, 1.02, 1.02, -0.02]});

    for (var i=0;i<50;i++) {
        var p = board.create('point',

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]});
for (var i=0;i<50;i++) {
    var p2 = board2.create('point', [function(){return Math.random();},function(){ return Math.random()}], {size:3, withLabel: false});
JXG.addEvent(document.getElementById('box2'), 'mousemove', function () { this.update(); }, board2);