Lesson goal: Draw Polylines in 3D

Previous: Drawing lines in 3D | Home | Next: Introduction

In a previous lesson, you learned how to draw lines in 3D.

In this lesson, we introduce a many line (or "polyline") function that will draw many lines and connect each of them together. You just have to supply the sequential endpoints through which to draw the lines. This allows you to draw 3D "spaghetti" like graphics. The function is called line3dx and accepts an array of 3D coordinates.

Move the mouse over a dotted box for more information.

You can find a list of color codes here. The 3D drawing area will appear under your code-editor. You might have to scroll down to see it.

Now you try. Mess around with the code a bit and see what you can come up with.

Type your code here:

See your results here:

When using this function to draw, Lua has an interesting construct called a "table," which is an array of arrays, which is what the {{x1,y1,z1},{x2,y2,z2}...} actually is.

The point? If you define an empty array, like p={}, then you can "push" (x,y,z) points into it, one by one like this: table.insert(p,{x,y,z}). See the example. Dismiss.

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.