mercredi 17 avril 2019

Is the Math.random() function actually a fractal?

I am following the quadtree tutorial from The Coding Train (YT), and I got my quadtree working and drawing! My problem is that the points in using Math.random()*canvas.width and Math.random()*canvas.height to create a random point on the canvas isn't giving me a random pattern of points, It's fractal (like the Sierpinski Triangle).

I've looked up the chaos game (thanks to Numberphile) and understand enough to know that Math.random() isn't working. Here is my code that is generating the points.

for(let i=0; i<100000; i++){
    var rx = Math.random()*canvas.width;
    var ry = Math.random()*canvas.height;
    let p = new Point(rx, ry, 2.5, i);
    qtree.insert(p);
}

If anyone knows an explanation that would help, am i using Math.random() incorrectly? Is there a better way to get a random point inside a square?




Aucun commentaire:

Enregistrer un commentaire