Skip to content

Bubble Wand

Let's write a program to design our own bubble wands, then print them!

Two 3D-printed bubble wands with ridged rings.


Overview

Instead of drawing a 3D model by hand, you'll write a program that builds one for you. In Tinkercad Codeblocks, each block adds, moves, or changes a shape, and pressing Play runs your program to draw the model. Over four class days you'll build the wand's ring, handle, and base, wire every size to a variable so one change can resize the whole wand, use a loop to add a ring of ridges, and export the design for the 3D printer.

Before you start

You'll need your Tinkercad login. Your design saves automatically, so each day you open the same Bubble Wand and keep going. A "Day 2 starts here" box marks each day's starting point, with a picture of what your screen should show before you begin.

You've got it when…

  • Pressing Play draws a ring with evenly spaced ridges, a handle, and a round base, all one color.
  • Every size comes from a variable, not a plain number, and no math block is inside another math block.
  • Each section of your code starts with a comment saying what it builds.
  • Changing Thickness once rebuilds the whole wand thicker.
  • Your design is exported as an .STL file and submitted.

Collaboration & AI

Work: On your own. Ask a neighbor for a hand if you're stuck, but build your own wand.

AI — AIAS Level 1, No AI: This lab is about learning the blocks by placing them yourself, variables and loops included, so set AI aside this time. What the levels mean.


Create a Codeblocks Project

  1. Go to Tinkercad and sign in.

  2. Click Create, then Codeblocks.

    The Create menu with Codeblocks highlighted.

  3. Click the random name at the top of the screen and rename your project Bubble Wand.

    The project name box at the top of the screen.


Build the Ring

  1. Drag a Cylinder the Cylinder block from Shapes into the workspace.

    The Add cylinder block, folded up.

  2. Click the arrow the expand arrow on the block to unfold its parameters, the numbers that control the shape.

    The cylinder block unfolded, showing Radius 10, H 20, Sides 48, edge 0, Edge Steps 1.

  3. Click Play the Play button.

    Your screen should look like this.

    A tall orange cylinder on the workplane.

  4. Change H (height) to 2.

    The cylinder block with H set to 2.

  5. Click the hole button the hole button on the block. A hole cuts away from other shapes instead of adding to them. This one will be the opening in the ring.

    The cylinder block with the hole button selected.

  6. Click Play.

    Your screen should look like this.

    A flat, striped hole disc on the workplane.

  7. Drag a second Cylinder under the first one, unfold it, and set its Radius to 12 and H to 1. Leave it solid.

    Two cylinder blocks: the hole with Radius 10 and H 2, and a solid one with Radius 12 and H 1.

  8. Click Play.

    Your screen should look like this.

    A thin orange ring: the solid disc with the hole cut out of the middle.

    Why the hole is taller

    The hole is 2 tall and the ring is only 1 tall, so the hole pokes out above and below and cuts all the way through. A hole exactly the same height can leave a paper-thin skin behind.

  9. Drag a Tube the Tube block under the second cylinder, unfold it, and set Radius 21, Wall Thickness 10, H 2, and click its hole button. This tube trims the outside of the ring to a clean circle.

    The tube block set to Radius 21, Wall Thickness 10, H 2, as a hole.

  10. Click Play.

    Your screen should look like this.

    The ring with the tube-shaped hole around it.

  11. Drag a Group Selection the Group Selection block from Modify under the tube. Group combines everything above it into one shape, and that's when the holes actually cut.

    The four blocks of the ring: hole cylinder, solid cylinder, hole tube, Group Selection.

  12. Click Play.

    Your screen should look like this.

    The finished ring.


Day 2 starts here

Open your Bubble Wand design in Tinkercad and click Play. Your screen should look like this. If it doesn't, finish Day 1 first.

The finished ring from Day 1.

Give the Sizes Names

Right now every size is a plain number. A variable stores a number under a name, so you can use the name everywhere and change the number in one place.

  1. Click Variables and click Create number variable….

    The Create number variable button.

  2. Name it InnerRadius with no spaces and click Create.

    The new variable dialog with InnerRadius typed in.

    Warning

    Variable names can't contain spaces. InnerRadius works; Inner Radius won't.

  3. Drag the Set block the Set block into an empty part of the workspace, above your ring blocks, and set InnerRadius to 10.

    The Set block with InnerRadius set to 10.

  4. Make three more variables the same way, and add a Set block for each under the first: Thickness 1, OuterRadius 11, and Overflow 5. The dropdown on a Set block picks which variable it sets.

    Four Set blocks: InnerRadius 10, Thickness 1, OuterRadius 11, Overflow 5.

    Warning

    The Set blocks must be above the ring blocks. Codeblocks runs from the top of the workspace down, so a variable has to be set before the shapes that use it.

  5. Drag the round InnerRadius block the InnerRadius variable from Variables onto the Radius of the first cylinder. It replaces the 10.

    The first cylinder with InnerRadius in its Radius slot.

  6. Drag a math block the math block from Math onto the H of the first cylinder.

    The first cylinder with an empty math block in its H slot.

  7. Drag Thickness into the first space of the math block.

    The math block reading Thickness + 0.

  8. Change the 0 to 1. The hole is now Thickness + 1 tall: always one taller than the ring, however thick the ring gets.

    The math block reading Thickness + 1.

  9. Set the second cylinder's Radius to OuterRadius + 1 and its H to Thickness, the same way.

    The second cylinder with Radius OuterRadius + 1 and H Thickness.

  10. Set the tube's Radius to OuterRadius + Overflow, its Wall Thickness to Overflow, and its H to Thickness + 1.

    The tube with Radius OuterRadius + Overflow, Wall Thickness Overflow, and H Thickness + 1.

  11. Click Play.

    Your screen should look like this.

    The ring, drawn from variables, looking exactly as it did before.

    So what did we gain?

    The ring looks the same. The difference is invisible for now: every size traces back to four named numbers. On Day 4 you'll change one variable and watch the whole wand rebuild itself.


Label Your Code

Comments are notes for people. The computer ignores them.

  1. Drag a Comment block the Comment block from Mark Up onto the top of your Set blocks and type Variables in it.

    A Comment block reading Variables above the Set blocks.

  2. Add a second Comment on top of the ring blocks that says The ring.


Day 3 starts here

Open your Bubble Wand and click Play. The wand still looks like the ring from Day 1, and your code should start with a Variables comment above four Set blocks, then a The ring comment above the ring blocks. If it doesn't, finish Day 2 first.

A Comment block reading Variables above the Set blocks.

Build the Handle

The handle is a long, thin cylinder lying on its side. We'll need two new variables for it.

  1. Create a variable named Length and add a Set block at the bottom of your Variables section: Length to 30.

  2. Create a variable named HalfLength. Add a Set block for it, drag a math block into its slot, and build Length / 2. Click the + on the math block to change it to /.

    The Variables section, now ending with Set Length to 30 and Set HalfLength to Length / 2.

    Why HalfLength gets its own variable

    Math blocks can sit inside other math blocks, but that's where bugs hide. These two blocks read the same, and they give different answers:

    Two math blocks that both read InnerRadius + Length / 2, nested differently.

    Codeblocks always does the inside block first. With InnerRadius 10 and Length 30, the top one is 10 + 15 = 25 and the bottom one is 40 / 2 = 20. You can't tell which you built by reading the words; you have to look at the outlines. We skip the problem: give the middle step its own variable, and every math block only ever holds two things.

  3. Start a new section below the ring: a Comment that says The handle, with a Cylinder under it. Unfold the cylinder and set Radius to Thickness.

    The handle cylinder with Radius set to Thickness.

  4. Set its H to Length.

    The handle cylinder with H set to Length.

  5. Click Play.

    Your screen should look like this.

    A tall thin cylinder standing up in the middle of the ring.

  6. Drag a Rotate around block the Rotate block from Modify under the cylinder. Leave it at Axis x and 90 degrees.

    The handle section with the Rotate block under the cylinder.

  7. Click Play.

    Your screen should look like this.

    The handle lying flat, poking through the middle of the ring.

  8. Drag a Move block the Move block from Modify under the rotate.

    The handle section with the Move block added.

  9. Drag a math block into the Y slot of the Move block.

    The Move block with a math block in its Y slot.

  10. Fill it in: InnerRadius + HalfLength. That slides the handle out of the middle until its end just touches the inside of the ring.

    The Move block with Y set to InnerRadius + HalfLength.

  11. Click Play.

    Your screen should look like this.

    The handle attached to the edge of the ring.


Build the Base

  1. Create one more variable, HandleEnd, and set it at the bottom of your Variables section to InnerRadius + Length. That's how far the handle reaches from the center.

    The Variables section, now ending with Set HandleEnd to InnerRadius + Length.

  2. Start a new section: a Comment that says The base, with a Torus the Torus block under it. Unfold it and set Radius to InnerRadius and Tube to Thickness.

    The torus block with Radius InnerRadius, Sides 48, Tube Thickness, Steps 24.

  3. Click Play.

    Your screen should look like this.

    A blue ring sitting in the middle of the wand's ring.

  4. Add a Move block under the torus with Y set to HandleEnd + InnerRadius.

    The base section with Move Y set to HandleEnd + InnerRadius.

  5. Click Play.

    Your screen should look like this.

    The torus at the far end of the handle.

  6. Click the color circle on the torus block and pick the same orange as the rest of the wand.

    The torus block with its color changed to orange.

  7. Click Play.

    Your screen should look like this.

    The wand, all one color.

Checkpoint

Ring, handle, base, one color, all from code. Your whole program should look like this.

The complete program: Variables, The ring, The handle, and The base.


Day 4 starts here

Open your Bubble Wand and click Play. Your screen should look like this. If it doesn't, finish Day 3 first.

The wand, all one color.

Adding Ridges

Look back at the printed wands at the top of this page. Their rings have ridges. Placing those by hand would be tedious, and tedious jobs are what computers are for: a loop repeats a set of blocks for you.

A close-up of the ridges around the ring.

Each ridge is a small box: half as wide as the ring is thick, long enough to poke out both sides, and twice as tall. We'll give those three sizes names first, so the box block stays simple.

  1. Create three variables and set them at the bottom of your Variables section: RidgeWidth to Thickness / 2, RidgeLength to OuterRadius * 2.2, and RidgeHeight to Thickness * 2. Click the + on a math block to change it to / or *.

    Three Set blocks: RidgeWidth to Thickness / 2, RidgeLength to OuterRadius * 2.2, RidgeHeight to Thickness * 2.

  2. Drag a Box the Box block under the Group Selection at the end of The ring. Unfold it and set W to RidgeWidth, L to RidgeLength, and H to RidgeHeight.

    The Box block under Group Selection with W RidgeWidth, L RidgeLength, H RidgeHeight.

  3. Click Play.

    Your screen should look like this.

    The wand with one ridge box lying across the ring.

    One ridge. Now let's repeat it around the ring, like the spokes of a wheel.

  4. Drag a Count with block the Count with loop block from Control into an empty spot, then drag your Box into the loop's mouth (the gap after Do). Snap the loop under Group Selection.

    The Count with loop under Group Selection, with the Box inside it.

    The loop's counter

    The loop creates a variable for us named i. Each time around, i is set to the next number in the from and to range, and we can use it inside the loop.

  5. Drag a Rotate around block the Rotate block inside the loop, under the box.

    The Rotate block inside the loop, below the Box.

  6. Change Axis x to Axis z, then drag the round i block the i variable from Variables onto the by number.

    The Rotate block reading Rotate around Axis z by i.

  7. Set the loop to count from 0 to 179 by 10.

    The loop set to count with i from 0 to 179 by 10.

  8. Click Play.

    Your screen should look like this.

    The wand with ridges every 10 degrees.

    The loop adds a box and turns it i degrees, for every i from 0 to 179 in steps of 10. Each box pokes out both sides, so 180 degrees covers the whole ring.

  9. Change the by to 12 to leave a little more space between ridges.

    The loop set to count by 12.

  10. Click Play.

    Your screen should look like this.

    The wand with ridges every 12 degrees.


Trimming the Middle

The ridges cross through the middle of the ring. A hole cylinder, a little smaller than the opening and taller than the ridges, will cut them back.

  1. Create two more variables and set them at the bottom of the Variables section: CutRadius to InnerRadius - RidgeWidth and CutHeight to Thickness * 3.

    Two Set blocks: CutRadius to InnerRadius - RidgeWidth, CutHeight to Thickness * 3.

    Order matters for minus

    InnerRadius goes in the left space and RidgeWidth in the right. RidgeWidth - InnerRadius is a negative number, and a cylinder with a negative radius is not a cylinder. For + and * the order doesn't matter; for - and / it always does.

  2. Drag a Cylinder under the loop, unfold it, click its hole button, and set Radius to CutRadius and H to CutHeight. Then drag a Group Selection under the cylinder.

    The loop, then a hole cylinder with Radius CutRadius and H CutHeight, then Group Selection.

  3. Click Play.

    Your screen should look like this.

    The wand with the ridge ends trimmed clean inside the ring.


One Change, Whole Wand

The wand looks a bit fragile. Let's make it thicker everywhere. Instead of changing every piece, we change one variable at the top of the program, and every block that uses it rebuilds.

  1. Change Set Thickness from 1 to 2.

    The first four Set blocks, with Thickness now 2.

  2. Click Play.

    Your screen should look like this.

    The whole wand rebuilt thicker, ridges and all.

    Checkpoint

    Ridges from a loop, and a thicker wand from one number. Your whole program should look like this. Compare it with the Day 3 checkpoint above: the only new blocks are in The ring and Variables.

    The complete program: Variables, The ring with the loop and cut, The handle, The base.

Tip

Try changing some other variables to customize your bubble wand. Bigger Overflow, longer Length, more or fewer ridges.


Preparing for 3D Printing

We need to export our design in a format the 3D printing software can use.

  1. Click Share the Share button in the upper right corner.

  2. Select .STL.

    The export dialog with the .STL option.

  3. Submit your downloaded .STL file in Google Classroom.


Turn It In

  • Your bubble wand's .STL file, submitted in Google Classroom.

Tinkercad saves the design itself to your account automatically; there is nothing else to upload.


Credit: Adapted and updated from this tutorial.


How It's Graded

This lab is worth up to 4 points. One score covers everything you turn in.

Score What it looks like
4 — Excellent The .STL opens as a complete wand: ring, handle, round base, and evenly spaced ridges trimmed clean inside the ring, all one color. Every size comes from a variable with no plain numbers left behind and no math block inside another; the ridges come from one box inside a Count with loop rotated by i; each section opens with a comment; and changing Thickness rebuilds the whole wand.
3 — Above Average A complete ridged wand with a slip or two: a plain number where a variable belongs, a section missing its comment, ridges that overlap because by stayed at 10, or a cut cylinder that leaves stubs.
2 — Average A real gap: the wand is missing a part, the ridges were placed by hand instead of by a loop, the middle isn't trimmed, or the parts are sized with plain numbers instead of the variables.
1 — Below Average Only the ring draws, the program doesn't produce a recognizable wand when Play is pressed, or no .STL was exported.
0 — Failing No .STL submitted and no Bubble Wand design in your Tinkercad account, or a file that isn't a wand.