Molecules

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

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 

bulletBrowse source extract
bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

Perhaps a temperature control which would increase or decrease molecule speeds to  change the kinetic energy.    
Since our "system" does not gain or lose heat, the total kinetic energy should remain constant.  That is to say, the total kinetic energy of the system (the sum of the kinetic energies of all the molecules)  should remain constant.  I wonder if it does.  
As a coding exercise, it would be interesting to see if the processing power required to move the molecules could be reduced - perhaps making TMolecule a Tshape descendant  so that  images are maintained as bitmaps rather than being redrawn each time. 

 

Original Date: January 4, 2003 

Modified: May 15, 2018

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.