Density, buoyancy, coding & art

By George Gadanidis & Chris Yiu — Western University


Will it sink or will it float?

What floats and what sinks (buoyancy), and why (relative density), are interesting ideas for young children, that capture their imagination and get them thinking.

Take a tiny pebble and throw it in a pond. It sinks.

Take a big log and throw it in the same pond. It floats.

Why? One grade 1 student replied, “They are made of different stuff.”

[Note: This is a work in progress. We will make edits as we try it with young students and their teachers. Please send feedback to George Gadanidis at Thank you!]


Let’s make it sink with code

The coding app we’ll use is at

This is our latest version. It comes with code for 2 objects, which you can run to see the effect, and then edit to create new effects.

Here is the code for Object 1 (with explanatory notes)

This is the code for Object 2. Notice how it’s different from the code for Object 1.

  • Its density is 0.9, so it will float!
  • Its elasticity is 100%, so it will bounce back to the height from which it’s dropped.
  • It includes code that will change the parameters of any Object it collides with.

Then click on Run All Code to get this result.

Notice that objects bounce. The Canvas is like a box and they bounce inside.

Notice what happens when the two Objects collide!



Experiment by changing the values of parameters. The click on Run All Code and Clear Paths.

Or add another object (click on Add Object).

  • Create code for this object
  • Notice that you can also Copy/Paste code from other Objects , and the edit it


Examples using variables

Example 1


Example 2


Write your own code

Write code to create a density/buoyancy artwork.

Click on Save Image to save and share.