Lesson goal: 3d graphics the depth

Previous: Introduction to 3D graphics | Home | Next: 3D graphics and the camera

In the last lesson you saw how to draw spheres using three dimemsional coordinates. In this lesson, we wanted to be sure you understand the z-coordinate, and how it give you the added element of "depth" in your graphics.

Let's again use scene3d() and sphere() to draw, but let's move a single sphere up and down along the z-axis.

Try these two tests:

Test #1: Start by drawing a sphere at (0,0,80) with a radius of 5. Then change the 80 to -80, as in (0,0,-80). What do you notice?

Test #2: Try drawing two spheres, like this:

  1. Draw a sphere at (0,0,50) with a radius of 10 in a red color (ff0000).
  2. Keeping the code in place for that sphere, draw another sphere at (10,0,30) with a radius of 10, in a green color (00ff00).
What do you see? Do you see the "depth" that 3D graphics offers?

Now you try. Try running through these two tests, so you can see the depth and perspective given by 3d graphics.

Type your code here:

See your results here:

And remember, you are programming now. You can place lots of spheres using a for-loop like this:

c = 0
for z=80,-80,-15 do
if c % 2 == 0 then
color = "ff0000"
color = "00ff00"

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.