Compensation is the observed nature law, describing the bending of mushroom stems and some parts of plants when they try to orient themselves properly in the Earth gravity field. If plant or mushroom is turned horizontally, parts almost immediately start to bend as the organism tries to orient itself "correctly": stem or cap up and roots or base down.
These movements that (given enough time) usually restore the proper orientation are the complex, very well coordinated reaction. As a rule, bending starts from the top (apex) of the stem where sense of orientation is the most developed. Similarly, in mushrooms it also starts high on the stem, right below the cap. This top tip region produces signals (not yet fully understood) that propagate towards the more basal parts that also start to bend.
Sections below the tip seem less sensitive to they orientation and mostly bend following directions from "the up". However they do have some sensitivity of they own that helps to react faster in case when the orientation is seriously disturbed, like turning all stem horizontally.
This reaction have evolved through millions of years and performs its role very well. Bending from the tip restores the tip (or mushroom cap) into proper orientation very quickly. However after fixing the "critical issues" the organism tries to get more optimal shape, concentrating the most of the curvature near the base and making the top sections straight again.
The most straightforward way to explain the process of compensation and orientation in the gravity field in general would be to explore structure of all tiny parts of the system involved, understand molecular and other mechanisms of this reaction and then derive explanation from these established data. Unfortunately, the amount of available data is not sufficient for this type of exploration, and alternative approaches need to be used. Good results were obtained through the mechanism of mathematical abstraction that allows to describe processes without knowing full details about they physical nature (same equation describes oscillations of spring, pendulum and electric oscillator equally well).
Then described in the form of mathematical equations, the reaction of orientation usually includes the following components:
The provided applet allows to experiment by turning on and off various parts the basic hypothesis. It also provides some built-in sets of the real experimental data, representing reactions of stems "as is" or after treatment with chemical compounds that are known to alter some important parts of the biological systems even in extremely low concentrations. It is a part of the research project that was performed in Manchester university in about 1998.
See the project page at  website for more detailed literature overview, verbal and mathematical descriptions of the models involved and extended simulations using Java applets.