Introduction: Learn Codeblocks While Making a Bubble Wand
While chatting with teachers, I found many weren't inspired by starting students 3D design journey with name tags or key chains. Through many conversations, two projects stood out as much more interactive, fun, and usable once the project was done. One of them was 3D Printed Bubble Wands like these by Penolopy Bulnick which inspired this project. The other was a stencil that I'll talk more about in a future Instructable.
I wanted to try my hand at making a coded version of the bubble wand for anyone wanting to learn Codeblocks. You can find the full editable code here, and the instructions below.
Supplies
- Computer with internet access
- Tinkercad
- 3D Printer (if you want to print the final model)
Step 1: Sign Into Tinkercad and Create a New Codeblocks Design
Sign into your Tinkercad account and click “Codeblocks” in the left-side menu. Then click the “Create New Codeblock” button.
Click “New Design”
Rename your project to “Bubble Wand”. Take a moment to notice that there are three columned areas in the Codeblocks interface. The leftmost side in your Blocks Panel, the middle is your Blocks Editor, and the right is your 3D Viewer. You can drag the bar between your Blocks Editor and 3D Viewer if you want to focus more on one then the other.
Step 2: Create the Bubble Blower
Drag a Cylinder to the Blocks Editor and click the arrow on the right to expand the drawer and see which parameters you can control.
Click the Play button in the top menu. This will run the code in the Blocks Editor. You can adjust the speed to the left of the play button if you want the code to run faster. You can use the Step button to the right, to step through the code one block at a time. Note: These directions don’t say to click play in every step, but it is recommended that you click play more often when you’re starting out to see what the modifications you’re making are doing.
Change the Cylinder Height to 2 and click the Hole icon to turn the shape into a hole. Click Play.
Add another Cylinder with Radius 12, and a Height of 1.
Add a Tube with Radius of 21, Wall thickness at 10, a Height of 2, and check the hole button.
Add Create Group from the Modify section (colored purple) in the Blocks Panel. Click Play. The blower should be done.
A few notes on the design. The holes are sized a little larger than what they’re holing out. This is to prevent issues when a hole and a shape have identical edges. One unit in Codeblocks is equivalent to about 2 cm, so if you want your bubble wand to be a specific size when all is done, you can now convert.
Step 3: Creating and Adding Variables
Variables help by allowing us to quickly access values that are going to be used multiple times throughout the project. Scroll in the Blocks Panel to the Math section (green), drag Create Variable above the current code in the Blocks Editor. Variables need to be defined before we use them.
Click Item, then click “Rename variable…” in the dropdown. Enter InnerRadius (no spaces) as the name and enter 10 as the associated variable.
Repeat the previous two steps to add Variables for Thickness (with a value of 1), OuterRadius (11), and Overflow (5).
Once the variables are created, you’ll see them at the bottom of the Blocks Panel (blue). Drag out InnerRadius and set that as the Radius for the first Cylinder.
Drag the green (0 + 0) block and place that into the height for the first cylinder, then place the Thickness variable in one of the 0 spots, change the 0 to a 1, and click the plus drop down to change it to multiplication. Height should now be (Thickness * 1).
Change the second Cylinder so the Radius is (OuterRadius + 1) and the Height is (Thickness).
Change the Tube so the Radius is (OuterRadius + Overflow), Wall Thickness to (Overflow), and H to (Thickness + 1). Note: Since we’re using (Thickness * 1) more than once, turning it into a new variable would be recommended. By doing this, in the future, if we change the Thickness variable, it will update the new variable for you. We’ll cover this more later but will not be modifying this variable.
Click Play and make sure your blower looks the same.
Step 4: Creating the Bubble Wand
Before adding the wand, it’s important to ensure we can find what we’re looking for in the future. This is especially important if we have complex code. So, from the very bottom of the Blocks Panel, drag out a Comment Block and attach it to the top of your Variables. Click the text area and change the text to Variables.
Add two more comments in a similar fashion. Attach one above your first Cylinder and name it Wand Blower. Then attach one at the end of your current code and name it Wand Handle. In the future, when you open this sketch, you’ll be able to easily find the different parts of the code.
Drag in a Cylinder and change its Radius to (Thickness). Click Play and see what happens.
There currently isn’t a variable set for how long our wand will be. So, drag a new Create Variable to the bottom of your Variables section and name it Length and make it equal 30.
Change the Cylinder Height to (Length).
Add a Rotate block from the Modify (purple) block menu, at the end of your blocks. Make sure the Rotate Around is set to Axis x. Click Play.
Add a Move block after Rotate, so we can place the wand at the base of the Blower. Placing the wand is going to require more than one mathematical operation. It is useful to think that Codeblocks places a parenthesis around each (0 + 0) function. This means if you want to write the equations 3-2*5, you will have to combine it such that it reads as follows in blocks (3 – (2 * 5)). You can combine as many (0 + 0) blocks together as you like, just be very aware of how you’re combine multiple arithmetic blocks together.
Add two (0 + 0) blocks. Make one (InnerRadius + 0) and the other (Length / 2).
Move (Length / 2) into the 0 of (InnerRadius + 0), to make the final equation (InnerRadius + (Length / 2)).
Drag your equation into the Y: variable of the Move block. Click Play.
At the center point of your Workplane, x=0, y=0, and z=0. Since we added the equation to the Y value in the previous step, our Wand was placed at the top of our Blower. To shift our wand below our Blower, we can drag in one more (0 + 0), and move our entire equation into the second 0, and change the plus to a minus, resulting in (0 - (InnerRadius + (Length / 2))). This is purely an aesthetic choice as the screen can be rotated as well. Even though it’s aesthetic, ensure you make this modification or the following instructions will not work.
Step 5: Adding a Bubble Handle
For the Handle, we’re going to use a different method then was used for the Blower. Add a Comment to the end of your code and update the text so you know what you’re doing.
Drag a Torus from the Blocks Panel and make the Radius equal (InnerRadius), the Tube equal (Thickness), and change the color so it matches the rest of the wand.
Attach a new Move block to the end of your code.
Make Y = (0 – (InnerRadius + (Length + InnerRadius))). Try it first, and if you get stuck, continue reading this step. Start by grabbing 3 (0 + 0) blocks. Place them so they look like a staircase descending to the right, with the ending 0 of the step above aligned with the initial 0 of the step below. From left to right make each block as follows: (0 – 0), (InnerRadius + 0), (Length + InnerRadius). With the variables entered, starting at the bottom, drag each steps equation into the ending 0 of the step above it.
Move final equation into the Move Y: field. Click Play.
Step 6: Centering Our Wand in the Workplane
To move everything we’ve placed so far; we need to combine it all together into a single shape. To do that, drag a Create Group block to the end of the current code.
Add a Move next and pull out 2 (0 + 0) blocks. Make one (InnerRadius + 0), and the other (Length / 2).
Combine your equations to be (InnerRadius + (Length / 2)), and place that into the Y: field. Since we’ve been moving our Wand and Handle in a negative Y direction, by adding half that value back, the entire model shifts back up to center.
Step 7: Adding Ridges
While we could call this a completed bubble wand at this point, if you look at one purchased from the store, you’ll notice ridges around the bubble blower. Since that’s the case, let’s add some to our bubble wand as well. This is going to be part of the Blower section, so click and drag the Wand Holder comment down so there’s a space after the Wand Blower section to add more code.
Go to the Control section (orange) in the Blocks Panel and add a Count loop after the last Group in the Wand Blower section.
Drag a Box into the Count loop.
Change Width to (Thickness / 2), Length to (OuterRadius * 2.2), Height to (Thickness * 2), and the color to match the rest of the wand. Multiplying by 1.9 keeps our rectangles from going outside the Blowers outer radius.
Add a Rotate block after the Box block inside the Count loop. Change the Axis to Z, and the by (90) Degrees, to by (i) Degrees. When you pulled in the count loop it creates a variable for you (the default is i). You can change that variable the same way you change others if you prefer.
Looking at the top of the Count loop, you can see: Count with (i) from (1) to (10) by (1). The Box rectangles are rotating around the Z axis by an angle of i. Knowing this, we need to change the (i) variable to change the rectangle rotation. Since our rectangle goes all the way from one end of our blower to the other, we only need to rotate by 180 degrees instead of 360. Change the Count loop to read: Count with (i) from (0) to (179) by (12). This will count by 12’s, starting with 0. Note: if you decide the change the by (12) variable, ensure that you enter a value that is divisible evenly into 180 to ensure an even distribution of rectangles (try some different values to see what happens).
After the Count loop, add a Cylinder, make it a hole, and change Radius to (InnerRadius – (Thickness / 2)), and Height (Thickness * 2). Click Play. Note: The rectangles are a little thin, we'll fix that in the next step.
Step 8: Doing More With Variables
Go to the Variables section in the Blocks Editor, and the Math section in the Blocks Panel. Drag the Random between (0) and (10) to the Create Variable: InnerRadius block. Set the random values to (9) and (14). This will randomize the Blower size every time Play is clicked.
Now we’ll adjust the rest of the variables to update depending on the InnerRadius. Change Thickness variable to: (InnerRadius / 5). Note: This will double the thickness of what is was before, so there will be a noticeable change when modifying this variable. See the original thickness by setting Thickness to (InnerRadius / 10). We're making this thicker so that a 3D printer is better able to print the ridges, but play with this as you like.
Change OuterRadius variable to (InnerRadius + Thickness).
Change Length variable to (InnerRadius * 4).
Click Play a few times (without changing the viewer size) to watch how the wand size changes.
Step 9: Next Steps
There are a few options that can be taken with your model. If you click Export, you can export to an STL for 3D printing or as a Shape which will save it to Your Designs in Tinkercad’s 3D Editor.
Alternatively, Click share to save a PNG image of the model or export the building of the model into an animated GIF.
The STLs linked below are examples of the bubble wand when the Inner Radius was set to 7, 10.5, and 14.
Step 10: Thoughts
The bubble wands came out really well, and by building connections between variables, it's really simple to make modifictions to test ideas, then revert if needed. When testing against the bubble wand that came with my bubbles, these homemade wands seemed to work better (if not just as good). I'm very happy with the final results and think in the future I might try to come up with a way of doing different shapes.