NetLogo banner

 Contact Us

 Modeling Commons

 User Manuals:


NetLogo Models Library:
Sample Models/Chemistry & Physics/GasLab/Unverified

Note: This model is unverified. It has not yet been tested and polished as thoroughly as our other models.

(back to the library)

GasLab Pressure Box

[screen shot]

If you download the NetLogo application, this model is included. (You can also run this model in your browser, but we don't recommend it; details here.)


This model simulates the behavior of gas particles trapped in a container with a fixed volume, such as inflating a bike tire. The number of particles in the box can be changed by adding particles through a valve on the side.

This model is one in a series of GasLab models. They use the same basic rules for simulating the behavior of gases. Each model integrates different features in order to highlight different aspects of gas behavior.

The basic principle of the models is that gas particles are assumed to have two elementary actions: they move and they collide - either with other particles or with any other objects such as walls.

This model is part of the Connected Chemistry curriculum, which is part of the Modeling Across the Curriculum (MAC) Project.


The particles are modeled as hard balls with no internal energy except that which is due to their motion. Collisions between particles are elastic. Particles are colored according to speed --- blue for slow, green for medium, and red for high speeds.

Coloring of the particles is with respect to one speed (10). Particles with a speed less than 5 are blue, ones that are more than 15 are red, while all in those in-between are green.

Particles behave according to the following rules: 1. A particle moves in a straight line without changing its speed, unless it collides with another particle or bounces off the wall. 2. Two particles "collide" if they find themselves on the same patch (the world is composed of a grid of small squares called patches). 3. A random axis is chosen, as if they are two balls that hit each other and this axis is the line connecting their centers. 4. They exchange momentum and energy along that axis, according to the conservation of momentum and energy. This calculation is done in the center of mass system. 5. Each turtle is assigned its new velocity, energy, and heading. 6. If a turtle finds itself on or very close to a wall of the container, it "bounces" -- that is, reflects its direction and keeps its same speed.

Pressure is defined as the force per unit area (or length in this two-dimensional model). Pressure is calculated by adding up the momentum transferred to the walls of the box by the particles when they bounce off and divided by the length of the wall, which they hit.

Initially, the particles are not moving, and cannot hit the wall. Therefore the initial pressure is zero. As the particles start moving, they all first have the same speed in random directions. As the particles repeatedly collide, they exchange energy and head off in new directions, and the speeds are dispersed --- some particles get faster, some get slower.


Initial settings

  • BOX-SIZE: The size of the box as a percentage of the world-width
  • INITIAL-NUMBER-PARTICLES: the number of gas particles in the box when the simulation starts

The SETUP button puts in the initial conditions you have set with the sliders. Be sure to wait until the SETUP button stops before pushing GO.

The GO button runs the code again and again. This is a "forever" button.

Additional settings

COLLIDE?: determines whether or not the particles collide among themselves ADD PARTICLES: pressing this button adds particles to the container through a valve, before and while the model is running NUMBER-TO-ADD: number of particles that are added to the box with each press of the "ADD PARTICLES" button


  • NUMBER OF PARTICLES: the number of particles in the box
  • PRESSURE: the pressure of the gas particles in the box
  • AVERAGE SPEED: average speed of the particles.
  • AVERAGE ENERGY: average kinetic energy of the particles.


  • PRESSURE: plots the pressure in the box
  • PARTICLE COUNT: plots the number of particles in the box
  • WALL HITS PER PARTICLE: plots the number of times a particle hits a wall every big tick


What is happening to the particles in the box as a new group of particles is injected? How is this related to the way pressure changes over time?

Can you observe collisions with the walls as they happen (you can pendown a particle or slow down the model)? For example, do the particles change their color? Direction?

Can you relate what you can see happening to the particles in the box with changes in pressure? The average speed? The average energy?

Why does the pressure fluctuate, even though the number of particles is the same? How long does it take for the pressure to stabilize? Does the number of particles in the box affect this time?

In what ways is this model an incorrect idealization of the real world?


Try different settings, especially the extremes. Are the particles behaving in a similar way? How does this effect the pressure? The energy?

How are the number of particles and the pressure in the box related to each other? Can you quantify this relationship? Does it change if collisions among particles are removed?

Does the same relationship hold for the number of wall hits per particle and the number of particles? Why? How are the two relationships connected?

Can you make the pressure graph smooth? Can you do it in more than one way?

The ideal gas equation shows that when keeping a constant temperature and volume, increasing the number of particles increases the pressure as well. Keeping a constant temperature means that the average kinetic energy of the particles, does not change, nor does their average speed. How is this related to the behavior of particles that you have seen so far? Are there any other observations that could be made to test this relationship between the number of particles and the pressure?

Notice that the pressure does not go up immediately after particles are added. What is the reason for this delay? Try adding particles into the box in different ways to increase or decrease this delay. Can you think of real-life situations, with a similar delay?

Sometimes, when going up in an elevator, airplane or up a mountain we feel a 'popping' sensation in our ears. This is associated with changes in pressure. Can you relate between this model and these changes in pressure? Are the temperature and volume constant in this situation?


What would happen if particles were added continuously rather than instantly? Add a switch that allows for particles to continuously be added to the box.

Can you "puncture" the box, so that particles will escape?

What would happen if the box were heated? How would the particles behave? How would this affect the pressure? Add a slider and code that increases the temperature inside the box.

If you could change the shape of the box, so that the volume remains the same: Does the shape of the box make a difference in the way the particles behave, or the values of pressure?


This model was developed as part of the GasLab curriculum ( and has also been incorporated into the Connected Chemistry curriculum (


If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:


Copyright 2002 Uri Wilensky.


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at

This model and associated activities and materials were created as part of the project: MODELING ACROSS THE CURRICULUM. The project gratefully acknowledges the support of the National Science Foundation, the National Institute of Health, and the Department of Education (IERI program) -- grant number REC #0115699. Additional support was provided through the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT -- NSF (REPP & ROLE programs) grant numbers REC #9814682 and REC-0126227.

(back to the NetLogo Models Library)