CREATOR(S): Diane Brancazio and Anya Timchenko, MIT Edgerton Center

**Lesson Overview**

How can I divide a piece into 3rds, 10ths, 17ths? How do quarters and 12ths compare? Investigate fractions and the math behind them! Use Codeblocks, the Autodesk coding environment in Tinkercad, to automatically create fractional pieces. View them or 3D print them. Make them in stock shapes or create your own shape.

This lesson explores the algorithms used to divide a standard piece into any number of fractions and line them up side by side to recreate the whole. Follow the code provided to step through the math, then come with your own shapes or algorithms.

**Essential Question: **

What algorithms can be used to divide an object and line the pieces up side by side?

What are the basic principles of coding and how are they useful in understanding mathematical concepts?

**Skills Taught: **

- Algorithms to divide parts into fractions
- Basic coding principles
- Coordinate planes with X, Y, Z axes
- 3D modeling

**Time Required:** 1 - 2 Hours

**Materials Needed: **

- Codeblocks workspace in Tinkercad
- 3D printer and filament

## Step 1: Understand the Project and Explore Codeblocks

**Context **

3D modeling can be useful for visualizing and exploring concepts without the need for objects to be 3D printed. This activity is based on Tinkercad Codeblocks where users “design with code” - making 3D models using draggable blocks of code. Codeblocks is easy for beginners to learn, and is a useful tool for learning and practicing coding and math as well as 3D modeling.

**Features of Codeblocks: **

- There are computation blocks for common math functions including: ( ) + - * /.
- Objects can be moved around the design space on standard X, Y, Z axes, and can be scaled along those axes as well.
- Designers can create and set variables for objects and for mathematical quantities and can call them in the math computation blocks.
- Count and Repeat loops are available for replicating objects easily
- All the usual Tinkercad 3D modeling capability of building with primitive shapes that can be solid or holes, and grouping to create new shapes.

*************************************************************************

The first step is to get familiar with the block-based programming environment in Tinkercad Codeblocks. Watch the Quick Start Guide on the Codeblocks site to learn how to snap and unsnap blocks. Explore and practice with these investigations:

**1. The Workplane and the Origin**

a. The Workplane measures 200 mm x 200 mm. The Origin is the center point where X = 0, Y = 0, and Z = 0

b. Objects come into the Workplane with their center points on the Origin. To set objects to specific positions, it is necessary to shift them in the X, Y, and Z directions. A convenient way to do that is to move the object by half its size in the X, Y, and or Z direction. Some objects allow you to set those Width, Length, and Height dimensions when they are created, others you can determine by moving them around.

**2. Moving**

a. Pick a Shape. Click and drag it into the black workspace.

b. Find the “Move” function. Click and drag it into the code space until it attaches to the Shape:

c. Play around with the X, Y and Z values individually.

- At what position do all shapes start when imported?
- What happens when you make a value negative?

*Examples:*

**3. Scaling**

a. Some Shapes will have an extended size arrow that imports the Shape with that specified size. Import and play around with the options to see how the object changes.

*Example:*

b. Locate and import the “Scale” function into the code space.

c. Attach the “Scale” to the Shape and play around with changing the X, Y and Z variables.

**4. Rotating**

a. Import a new Shape or use an existing Shape.

b. Find and add the “Rotate around” function to the Shape.

c. Rotate the Shapes around the X, Y and Z directions, switching the degree variable each time.

d. Try adding multiple rotations to the same shape.

Does the direction change the second/third time you rotate?

*Example:*

**5. Group**

a. Import two or more shapes.

b. Add a “Move”, “Rotate” or “Scale” one of them.

c. Turn one of the shapes into a hole.

d. Find the “Create group” function, add it to the shapes.

e. Group the shapes as followed:

- Solid grouped to solid. Overall shape: Solid.
- Solid grouped to a hole. Overall shape: Solid.

**6. Define variable**

a. Import the “Create Variable” into the code space.

b. In the drop-down options, select “Rename Variable…” and rename as “Number pieces”. In the number box on the right, change the variable to anything between 1 and 10. (This number will be a reference for the repeat variable to refer to.)

c . Find and attach a “Count with” to the bottom of the “Create Variable”. The variable “i” is the index number used in the Count loop

d. Under “Data” find the “Number pieces”, and drag the code into the “10” box.

e. Import a “Shape”, a “Move”, and a computation block “0 + 0” found under “Math” into the code space. Change the + to any of the drop-down selection (+,-,*,/) and choose a number to move the shape by in the second number variable box. You can play the “0+0” blocks inside each other and play around with the math to see how the equation affects the X, Y, and Z movement.

*Here is an example of a math equation placed in the Y variable:*

*((5 + i) * number pieces)) The i stands for the “Count with” number variable and the number pieces references the number found in the “Count Variable”.*

f. Add the “Shape” and “Move” code into “Count with” and play the code.

g. Play around with the numbers under “Move”, and “Create Variable”. Try changing the 1 in “count with”, to see how it affects the code.

**7. Repeat variable.**

a. Find and import the “Repeat” function.

b. Add two or more “Set Color”.

c. Play around with the colors and see if you can make a glowing pattern.

You should now be comfortable enough with Codeblocks to easily follow the activity instructions. Have fun!

## Step 2: Create a Bar and Divide It Up Into Fractions

Create this code in your workspace to make a Whole Bar, and the variables you will use to divide it into any number of fractions.

The Whole Bar is 200 mm, the maximum width of the workplane. It is moved to the back of the Workplane with the Move block.

Choose the number of fractions you want to create and use math and coding operations to create fractional pieces and line them up.

- The variable “fraction” is the number of pieces to create. This is set by you, the coder, to any integer value.
- The variable “piece size” is calculated as (200 / fraction)
- The variable “count” starts at 0 and is incremented in the Repeat loop. It is used to calculate the amount to move the fractional pieces across the workplane in the X direction.

To easily create fractional pieces, use shapes where the Width (or Radius) can be set in the Add block, such as the Cube. The entire set of fractional pieces is created in a Repeat loop, which is executed “fraction” times.

- Add a basic cube with Width = piece size.
- Move it in the X direction by (piece_size / 2) and in the Z direction by 10, so that the piece is located at the Origin of the Workplane. Then move it by -100 in the X direction so it is at the left edge of the Workplane. All objects coming in will go to this location before they move to their place in the fraction line with the last Move.
- In the final Move block the X direction shift is calculated as (piece_size * count), while the Y direction shift is set by the coder to any convenient number.

Try different values for “fraction” and for the Y value in the last Move block, then move onto the next step.

Try different values for “fraction” and for the Y value in the last Move block, then move onto the next step.

## Step 3: Create Fractions With Shapes Defined by a Radius

Add this code after the previous code and create another fraction line. It is very similar to the previous code, except in this case the Cylinder is defined by a radius, which is half the width of the object, so in the Add, block set Radius to (pieces_size / 2).

The only other change is the Y shift in the last Move block.

## Step 4: Create Fractions With Any Other Shape

Now try some irregular shapes. Add this code after the previous code. Note that the star is defined by a radius, so once again in the Add block set Radius to (pieces_size / 2). You can also change the height. Can you make the height based on the radius?

Try different values for “fraction” and for the Y value in the last Move block. Create more fraction lines using shapes of your own design, or other basic shapes in the Codeblocks library.

## Step 5: Compare the Fractional Parts on the Screen or 3D Print Them

Create sets of fractions and look for relationships. Try setting fractions to 3,4,5,6,7,8, or to 3, 6, 9, 12, 15.

Make 1 set of fractions sit on top of another by changing the Z variable in the first Move block.

If the parts don’t touch, they can be exported and sent to a 3D printer.

The code described above can be found at https://www.tinkercad.com/codeblocks/60DTAWlKmSX

## Step 6: Project Extensions

Create new shapes for the Whole and for the fractions

Fill the entire Workplane with fractions in a pattern

**Thanks for trying our Instructable! **

We hope you had fun designing and sharing your charm chains. What did you make? We want to see! If you did this in a K-12 classroom, what subject was it in?

Send us an email or leave us a comment so we can see what you're making.

Visit our website k12maker.mit.edu to get resources for K-12 teachers:

- Maker skills workshops for K-12 educators - Spring, Summer, and Fall
- Makerspace Design Guide for K-12 Makerspaces
- Lists of Tools and Materials and illustrated charts to print and post
- Supervision and safety guidelines for shop administrators
- Training guides for common tools (including student checklists and refresher guides)
- Our Maker Methodology for designing Maker Projects for the core curriculum, including sample projects

## Discussions