Rectangles


In the rectangle demo a ball is moving randomly. A rectangle made of bricks is placed around the ball. Each brick detects the ball bumps and moves in the opposite direction in case of a shock; in this case, the brick also generates an event to let all others bricks move in the same way.

The difficulty is that in case of shock, all bricks must get the same information. Let us suppose that bricks are processed in a fixed order, for example, a clock-wise one; Two phases are then needed; in the first one, only the bricks after the one shocked can know existence of the shock (and then move accordingly); in the second phase, bricks that have not yet moved, have to do so.

In the reactive approach, one uses events to signal shocks. Events are thus automatically transmitted to all bricks by the reactive engine. Current instant is terminated only when all components have received (and processed) all produced events.

Here is the applet code.