Do the random walk!

What is this?

This is a simple random walk simulator using HTML5 + JS. I made this to demonstrate the beauty of randomness.


Steps: 0 Instances: 0




How does it work?

At each step, a random number i such that, 1 ≤ i ≤ 4 is chosen. Each number represents a direction: left, right, bottom, or top. We then walk towards the direction and draw the line. Each random instance is a JS "Object" and we keep track of these objects. For each tick of the timer, there are R steps executed, where R is the number of current instances. Random instances start anywhere in the canvas.

Performance?

Given that the draw event happens every t milliseconds, at every iteration, the complexity is O(R*d). O(d) is the time it takes to move and draw from the predecessor point pi to the new point pi+1 of a given instance on the canvas. R is the number of instances we are drawing. Naturally, the longer the step between pi and pi+1 , the more the performance is hindered, because more has to be drawn.

Why is there no CSS in this page?

O_O That's not the point

The code is on Github:

View the source on GitHub