Lesson goal: 3d graphics and the lighting source

Previous: 3D graphics and the camera | Home | Next: Drawing in 3D with cubes

In the last lesson you saw how you can set a camera position for your scene. Well guess what? You can also set the position of the lighting source for your scene.

That's right...with such graphics, you get to set where you want the light to be coming from, much as if with a real camera, you might be concered with where the sun is positioned during your shot.

When you call scene3d(), we default the light source to position to (x=0,y=0,z=1000), but with the light() function shown here, you can set the camera to any position you wish, and see how it affects your scene.

light(x,y,z)
Move the mouse over a dotted box for more information.

Let's again use scene3d() and sphere() to draw some spheres, but let's now move the light source around and see how things look in response.

First, try moving the light source left and right:

  1. Move the light to (100,0,100)
  2. Now to (-100,0,100)

What do you notice? Now try moving it up and down

  1. Move the light to (0,100,100)
  2. Now to (0,-100,100)

Neat, huh?

Now you try. Try moving the light source around and seeing how it affects your scene.

Type your code here:


See your results here:

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.