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:
Draw a sphere at (0,0,50) with a radius of 10 in a red color (ff0000).
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:
scene3d()
c = 0
for z=80,-80,-15 do
if c % 2 == 0 then
color = "ff0000"
else
color = "00ff00"
end
sphere(c*10,0,z,5,color)
c=c+1
end
Share your code
Show a friend, family member, or teacher what you've done!