A gravitational Eiffel tower outline with environment tool

Like a picture is confined to a frame, massPoints must not be allowed to go beyond the scope of the canvas, or the drawing would simply disappear. To prevent this, when the massPoints cross the limits of the drawing environment, they must bounce against invisible walls. These are defined by a new creation tool:

environment

The environment usually matches the frame of the canvas. It can also be dynamically redefined: walls can move inside (crop) or outside the canvas (mat), causing a dynamic cropping effect. With a great economy of means, this tool this tool can be used to create spectacular indirect effects:

The environment tool

The environment tool handles a massPoint who moves beyond a certain boundary. If a massPoint hits any border, it will bounce off and stay on the screen.

For accurate bouncing, the massPoint must be backtracked to the point where it first hits the wall. When the mass point hits a vertical boundary (right or left side), the horizontal velocity component is reversed. Analogically, when it hits an horizontal boundary, the vertical velocity is reversed. In order to let the mass point settle down, a bounce factor is applied to the reversed velocity, simulating the loss of kinetic energy. This is of course no hardcore physics, but a pretty realistic basic simulation technic.