// Below is the computer code of the gas molecule program. // The computer ignores everything written after two forward // slashes (like this line), so using these slashes is a good // way of writing comments for the reader. // The comments will tell you what each of the four parts of this // program does. //See the end of this program for ways in which it could be improved. // Parameters: int numMols = 500; int molSpeed = 5; int molRadius = 3; // Set-up other variables and matrices: int randomAngle, deltaX, deltaY; int [][] molStore = new int[numMols][4]; // (the 'molStore' matrix is a two-dimensional array // with 4 columns and numMols rows, and all numbers // stored in it an integer. The first two columns store // the current (x,y) position of each particle, and the // last two columns store the deltaX and deltaY values, // ie. the velocity of the particle.) // Set-up the dimensions and colours of the box, // set the frame-rate of the animation and then // run the Initialise function void setup() { size(500,500); stroke(0); smooth(); framerate(100); Init(); } // Initialise the simulation, stepping through each // row of the molStore matrix in turn, giving the // molecule a random position within the center of // the box and a random velocity vector void Init() { for(int i=0; iwidth-molRadius || molStore[i][0]height-molRadius || molStore[i][1]