NetLogo banner

NetLogo Publications
Contact Us

Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Farsi / Persian


NetLogo Models Library:
Curricular Models/Connected Chemistry

(back to the library)

Connected Chemistry 7 Ideal Gas Law

[screen shot]

If you download the NetLogo application, this model is included. You can also Try running it in NetLogo Web


This model explores the relationship between the variables in the ideal gas law (number of particles, container volume, gas pressure, and gas temperature). This model is part of the "Connected Chemistry" curriculum which explore the behavior of gases.

Most of the models in the Connected Chemistry curriculum use the same basic rules for simulating the behavior of gases. Each model highlights different features of how gas behavior is related to gas particle behavior.

In all of the models, gas particles are assumed to move and to collide, both with each other and with objects such as walls.

In this model, the gas container has an adjustable volume, adjustable number of particles, and adjustable temperature of the gas.

This model helps students study the representations of gas pressure in the model and the dynamics of the gas particles that lead to increases and decreases in pressure. In this model, students can also look at all the relationships in the ideal gas law.


The particles are modeled as hard balls with no internal energy except that which is due to their motion. Collisions between particles are elastic. Collisions with the wall are not.

Particles can be color-coded by speed with the SHOW-SPEED-AS-COLOR? chooser. For example, selecting red-green-blue makes colors slow particles in blue, medium-speed particles in green, and fast particles in red.

The exact way two particles collide is as follows: 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.In this model, two turtles are aimed so that they will collide at the origin. 3. An angle of collision for the particles is chosen, as if they were two solid balls that hit, and this angle describes the direction of the line connecting their centers. 4. The particles exchange momentum and energy only along this line, conforming to the conservation of momentum and energy for elastic collisions. 5. Each particle is assigned its new speed, heading and energy.

As the walls of the box are heated, the sides of the walls will change color from a deep red (cool) to a bright red, to pink to a pale pink white (hot). The walls contain a constant heat value throughout the simulation.

The exact way particles gain energy from the walls of the box is as follows: 1. Particles check their state of energy (kinetic). 2. They hit or bounce off the wall. 3. They find wall energy and set their new energy to be the average of their old kinetic energy and the wall energy. 4. They change their speed and direction after the wall hit.


Buttons: SETUP - sets up the initial conditions set on the sliders. GO/STOP - runs and stops the model. MOVE WALL -will temporarily "pause" the model when GO/STOP is running and wait until the user clicks in a new location in the World & View for the orange wall of the gas container. The new location must be to the right of the current orange wall location (so as to permit adiabatic free expansion of the gas) ADD-PARTICLES - when pressed releases particles into the box while the simulation is running. WARM WALLS - incrementally warms the box walls each time it is pressed. COOL WALLS - incrementally cools the box walls each time it is pressed.

Sliders: INITIAL-NUMBER - sets the number of gas particles in the box when the simulation starts. NUMBER-TO-ADD - the number of gas particles released into the box when the ADD-PARTICLES button is pressed. INITIAL-WALL-POSITION helps adjust the initial volume by setting the location of the orange box wall.

Switches: COLLIDE? turn particle collisions on or off LABELS? turn particle id labels on or off

Choosers: SHOW-SPEED-AS-COLOR? allows you to visualize particle speed using a color palette. - The "blue-green-red" setting shows the lower half of the speeds of the starting population as blue, and the upper half as red. - The "violet shades" setting shows a gradient from dark violet (slow) to light violet (fast). - The "all green" setting shows all particles in green, regardless of speed. - The "custom color" setting, referenced in the Pedagogica version of this model, allows the user to modify the color of one or more particles, without having to worry that the particles will be recolored with each tick of the clock (as is the case for the other color options).

Monitors: CLOCK - number of clock cycles that GO has run. PRESSURE - the total pressure in the box. TEMPERATURE. - the temperature of gas. VOLUME - the volume of the gas container. Volume is computed based on what it would be using the 3D view. The can be visualized as the inner gas volume (yellow walls and orange wall) that is 1 patch width deep in the z direction. NUMBER - the number of gas particles in the container. AVERAGE SPEED - the average speed of the gas particles. TOTAL ENERGY - the total kinetic energy of the gas. AVERAGE ENERGY - the average kinetic energy of the gas particles.

Plots: - 1: TEMPERATURE VS. TIME: plots particle temperature inside the box over time. - 1: NUMBER VS. TIME: plots the number of gas particles inside the box over time. - 1: PRESSURE VS. TIME: plots the average gas pressure inside of the box over time. - 1: VOLUME VS. TIME: plots the volume of the gas container over time. Volume is computed based on what it would be using the 3D view. The can be visualized as the inner gas volume (yellow walls and orange wall) that is 1 patch width deep in the z direction.

  1. Adjust the INITIAL-NUMBER slider.
  2. Press the SETUP button
  3. Press GO/STOP and observe what happens.
  4. Wait until the gas temperature stabilizes.
  5. Press WARM WALLS or COOL WALLS a few times.
  6. Wait until the gas temperature stabilizes
  7. Press MOVE WALL. The particle motion will pause momentarily.
  8. Then move your cursor to a spot inside the WORLD & VIEW, to the right of the current position of the orange wall. Click on this spot and the wall will move and the particle motion will resume.
  9. Adjust the NUMBER-TO-ADD slider and press ADD PARTICLES.


The ideal gas law relationships can be established in this model, with careful data gathering and mathematical modeling.

Why are there multiple combinations of volume, number of particles, and temperature of the gas that give the same pressure?


What combination of variables gives the highest pressure?


The Connected Chemistry models include invisible dark particles (the "dark-particles" breed), which only interact with each other and the walls of the yellow box. The inclusion of dark particles ensures that the speed of simulation remains constant, regardless of the number of particles visible in the simulation.

For example, if a model is limited to a maximum of 400 particles, then when there are 10 visible particles, there are 390 dark particles and when there are 400 visible particles, there are 0 dark particles. The total number of particles in both cases remains 400, and the computational load of calculating what each of these particles does (collides, bounces, etc...) is close to the same. Without dark particles, it would seem that small numbers of particles are faster than large numbers of particles -- when in reality, it is simply a reflection of the computational load. Such behavior would encourage student misconceptions related to particle behavior.


See GasLab Models See other Connected Chemistry models.


This model is part of the Connected Chemistry curriculum. See

We would like to thank Sharona Levy and Michael Novak for their substantial contributions to this model.


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:

To cite the Connected Chemistry curriculum as a whole, please use:


Copyright 2005 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

(back to the NetLogo Models Library)