Problem Description
Molecules is a simulation of random
molecular motion. Several predefined setups illustrate
transfer of kinetic energy and Brownian motion.
Background & Techniques
This is one of the few programs here at DFF that I did not write.
Viewer Arne, a retired Science teacher and amateur Delphi programmer
thought it might interest me and he was right! It simulates
molecular motion for 5 predefined setups. Molecules are
defined with a mass and velocity which reflects their kinetic
energy. (Kinetic Energy = 1/2 m v2 ).
There is not much interaction with the program but it is kind of
fascinating to watch and could provide base code for further
projects.
The coding is straightforward - a TMolecule class defines the
mass, color, current position and current velocity of each molecule.
An array of these molecules is set in motion in the main processing loop
which calls three procedures: Move updates the molecule positions
for the next time increment; Reflect detects collisions with walls
and changes the sign of the velocity component (x or y) which caused
the collision; and Collisions, the most complex part of the
job, detects collisions between molecules and determines
their new velocities. I'll let you examine the code for
details.
A delay routine in the loop prevents molecule positions from
being updated more than 10000 times per second. Unless
you have a fast computer, excessive speed will probably not be a
problem - molecules on my 255mhz laptop move like they are really
cold!
Running/Exploring the Program