The Biham-Middleton-Levine traffic model is a self-organizing cellular automaton that models simplified traffic.
It consists of a number of cars represented by points on a lattice with a random starting position, where each car may be one of two types: those that only move downwards (shown as blue in this article), and those that only move towards the right (shown as red in this article). The two types of cars take turns to move. During each turn, all the cars for the corresponding type advance by one step if they are not blocked by another car.
Your task is to visualize this model as an animation. Here are some good demonstrations.
Input
A floating point number between 0 and 1 representing density, and two integers representing the displayed grid height and width. Assume inputs are valid, and parameters to a function or reading from user input are both fine.
Example: 0.38 144 89
(corresponds to image above)
Output
A grid, at least 80x80, that displays the animation of this model running. At the start, cars are randomly placed on the grid until the grid reaches the input density, with half red and half blue (that is density times total number of grid squares, rounded however you like). The density must be this value, which means you cannot fill each cell with density as a probability. For each step, one type of car either moves downwards or right, wrapping around if they go past the edge. The type of car that moves alternates each step. To make the animation viewable, there must be at least 10 ms between each step.
Rules
The cars can be any color or symbol as long as they are distinguishable from each other and the background, and each car type is the same color or symbol.
Console and graphical output are both allowed. For console output, any printable symbol is fine, but output must be as a grid of characters.
Please specify what kind of output you've produced if you don't have a screenshot or gif.
The simulation must run forever.
The output is a bit complex, so if you have any questions, please comment.