Option 1: Gas
Part 1: Set Up
1. Create a relevant backdrop using the paint editor and add instructions to the backdrop using the text tool, if desired.
2. Add a sprite (i.e., the “ball” sprite can serve as a representation of the particles) and delete all the costumes for that
sprite except for one. Use the paint bucket in the paint editor to set it to a solid colour to make interactions between
each particle sprite easier to detect.
3. In the orange Variables menu, click “Make a Variable”.
a. Name the new variable “Temperature” and select the checkbox so that the variable appears on screen.
b. When the variable appears on the project preview screen, right click it and select Slider. This will allow the
user to change the temperature in order to eventually impact the speed at which the particle sprites move.
c. You can reposition the variable on screen by clicking and dragging.
Part 2: Basic Particle Settings
1. In the area for the particle sprite, add the When Green Flag Clicked event block.
2. Use the Set () To () block from the variables menu and change it to match with the name of your temperature
variable. Setting it to a low number (i.e., 10) will make it so that when your code begins. the particles will already
be in motion.
3. Use the Set Size To ()% block to resize the particle sprite (i.e., if using the default ball sprite from Scratch’s pre-
designed sprites, a size of 50%-75% works well).
Part 3: Interactions Between Particles
1. Add a Forever loop from the control menu. Inside of the forever loop add the If on Edge, Bounce block to keep
particles within the limits of the screen.
2. Still inside of the forever loop, add an If () Then block combined with a Touching Color ()? block from the sensing
menu. Click on the pre-loaded colour and use the colour picker to select the exact shade of the particle sprite you
have created to ensure 100% accuracy.
3. Inside of the If () Then block, add the following blocks, which will make it so that when two particles bump into each
other, they turn in opposite directions and bounce away, creating the effect of an interaction:
a. Add the Turn () Degrees block and combine it with a Pick Random () to () block. Set the numbers to be
between 150 – 210. The direction of the turn does not matter.
b. Add the Move () Steps block and set it to approximately 10. You can play around with the number to see
what impact that has on your code, but a lower number (i.e., anywhere from 5 to 15) will make the
movement more realistic.
Part 4: Respond to Temperature Changes
1. Outside of the If () Then block but still inside of the Forever loop from part 3, add a Move () Steps block and insert
a () / () operator block.
2. Set the first blank space of the () / () block to the round block with your temperature variable name from the
variables menu. Set the second blank space to a value such as 10. This will make it so that as the temperature
variable is increased or decreased with the slider, the movement of the particle sprites will speed up or slow down
accordingly.
Part 5: Create Many Particles
1. Each particle sprite will have the exact same code. As a result, you can just duplicate the sprite you have already
created in order to make as many particles as you desire. To create a duplicate, right click on the icon of the sprite
in the sprite pane and select “Duplicate.” Remember that if you make any changes in a particle sprite you will need
to replicate those changes in all the other sprites.