Skip to content

Basket

Let's write a program that weaves a basket!

The finished basket: a ring of tilted hexagons standing on a round base.


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. This basket is 27 hexagon rings, each one turned a little more than the last. Placing those by hand would take all period, and one wrong click would show. You'll draw one ring, then let a loop repeat it around a circle, and use a variable to change how many rings there are with one number.

Before you start

You'll need your Tinkercad login. Your design saves automatically.

You've got it when…

  • Pressing Play draws a basket: a ring of tilted hexagons on a round base, all one color.
  • The hexagons come from one ring block inside a Count with loop, not from copies you placed by hand.
  • Changing frame once changes how many hexagons the basket has.

Collaboration & AI

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

AI — AIAS Level 1, No AI: This lab is about learning the blocks by placing them yourself, 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 Basket.

    The project name box at the top of the screen.


Build One Ring

  1. Drag a Torus the Torus block from Shapes into the workspace. A torus is a donut shape.

    The Add torus block, folded up.

  2. Click the arrow the expand arrow on the block to unfold its parameters, the numbers that control the shape. Set Radius to 60, Sides to 6, Tube to 2, and Steps to 6.

    The torus block unfolded: Radius 60, Sides 6, Tube 2, Steps 6.

    What the numbers do

    Radius is how big the ring is. Sides is how many straight edges it has; 6 turns the donut into a hexagon. Tube is how thick the ring is, and Steps is how smooth the tube is. Any shape would work here; the hexagon just weaves nicely.

  3. Click Play the Play button.

    Your screen should look like this.

    A large, thin hexagon ring lying flat on the workplane.

  4. Drag a Rotate around block the Rotate block from Modify under the torus. Change Axis x to Axis y and 90 to 50. This tilts the ring.

    The torus block with Rotate around Axis y by 50 under it.

  5. Click Play.

    Your screen should look like this.

    The hexagon tilted at an angle, half sunk into the workplane.

  6. Drag a Move block the Move block from Modify under the rotate. Set X to -20 and Z to 46.5. Leave Y at 0.

    The ring stack: torus, Rotate around Axis y by 50, Move X -20 Y 0 Z 46.5.

  7. Click Play.

    Your screen should look like this.

    The tilted hexagon standing on the workplane, off to one side.

    Why those numbers

    Z 46.5 lifts the ring so its bottom point just touches the workplane. X -20 slides it sideways, away from the center. When we spin copies of this ring around the center, that sideways gap is what makes the basket wider or narrower. Try it later.


Give the Count a Name

We're about to make a lot of these rings. A variable stores a number under a name, so you can use the name in your program and change the number in one place.

  1. Click Variables and click Create number variable…. Name it frame with no spaces and click Create. Drag the Set block the Set block into an empty part of the workspace above your ring blocks, and set frame to 27. This is how many ring shapes make up the basket.

    The Set block with frame set to 27.

    Warning

    Variable names can't contain spaces. frame works; frame count won't.

  2. Create a second variable named frameRot, and add its Set block under the first one. The dropdown on a Set block picks which variable it sets. Drag a math block the math block from Math into its slot, click the + and change it to /, type 360 in the left space, and drag the round frame block the frame variable into the right space.

    Two Set blocks: frame to 27, frameRot to 360 / frame.

    frameRot is how far to turn between one ring and the next. A full circle is 360 degrees, and we're dividing it into frame equal turns.

    Order matters for divide

    360 goes in the left space and frame in the right. These two blocks look alike, and they don't compute the same thing:

    Two math blocks: 360 / frame on top, frame / 360 below.

    The top one is 360 ÷ 27, about 13 degrees per ring. The bottom one is 27 ÷ 360, a tiny fraction of a degree, and all your rings would pile up in one spot. For + and * the order doesn't matter; for - and / it always does.


Repeat It Around

A loop repeats a set of blocks for you. Doing this by hand would be tedious, and tedious jobs are what computers are for.

  1. Drag a Count with block the Count with loop block from Control into an empty spot. Drag your ring blocks (the torus, rotate, and move together) into the loop's mouth, the gap after Do. Then snap the loop under Set frameRot.

    The Set blocks, then the Count with loop with the ring blocks 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.

  2. Change from 1 to 0, and drag the round frame block onto the to number. Leave by at 1. Now the loop counts from 0 up to whatever frame is.

    The loop reading Count with i from 0 to frame by 1.

  3. Drag a Rotate around block inside the loop, under the Move.

    A second Rotate around block inside the loop, below the Move.

  4. Change Axis x to Axis z. Drag a math block onto the by number, drag i the i variable into its left space and frameRot the frameRot variable into the right, and change the + to *. Finally, drag the X: Y: Z: block the X Y Z block from Math onto from Pivot and leave it at 0, 0, 0.

    The Rotate block reading Rotate around Axis z by i * frameRot Degrees from Pivot X 0 Y 0 Z 0.

    Why the pivot

    Without a pivot, Rotate spins a shape around its own center, and the ring would just turn in place. Pivot 0, 0, 0 is the center of the workplane, so each ring swings around the middle of the basket instead.

  5. Click Play.

    Your screen should look like this.

    The basket frame: a ring of tilted hexagons woven around the center.

    Each time through the loop, the program draws one ring, tilts it, slides it, and turns it i * frameRot degrees: 0 the first time, then 13, then 26, all the way around. With frame at 27, that's a full circle.

  6. Change Set frame from 27 to 12.

    The Set blocks with frame now 12.

  7. Click Play.

    Your screen should look like this.

    The basket frame with only 12 rings, a much looser weave.

    One number, and the whole basket rebuilt. frameRot changed too, because it's computed from frame.

  8. Change frame back to 27, or pick a number you like better.


Add a Base

A basket needs a bottom, and a flat bottom is easier to 3D print.

  1. Drag a Tube the Tube block from Shapes under the loop (below its mouth, not inside it). Unfold it and set Radius 20, Wall Thickness 14.5, H 3, Sides 24, and edge 1. Leave Edge Steps at 1.

    The tube block: Radius 20, Wall Thickness 14.5, H 3, Sides 24, edge 1, Edge Steps 1.

  2. Click Play.

    Your screen should look like this.

    The basket frame with a flat round base under it.

  3. Drag a Group Selection the Group Selection block from Modify under the tube. Group combines everything above it into one shape. Click the rainbow circle on the block, choose Presets, and pick a color.

    The tube block with Group Selection under it, its color set to green.

  4. Click Play.

    Your screen should look like this.

    The finished basket, all one color.

Checkpoint

One ring block, one loop, one basket. Your whole program should look like this.

The complete program: two Set blocks, the Count with loop holding the ring blocks, the tube, and Group Selection.

Make it yours

Every number in this program is a knob. Try frame at 40, the tilt at 30 instead of 50, Sides at 4 or 8, or X at -30. Press Play after each change and see what it did. If you break it, change the number back.


Turn It In

  • Nothing to upload today. Tinkercad saves your Basket design to your account automatically, and you'll show it on your screen when asked.

Credit: Adapted and updated from Tinkercad's Basket example.


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 Pressing Play draws a complete basket, rings and base, in one color; the rings come from one ring block inside a Count with loop rotated by i * frameRot around pivot 0, 0, 0; and changing frame rebuilds the basket with a different number of rings.
3 — Above Average A complete basket with a slip or two: the loop's to is a typed number instead of frame, the base didn't get grouped in, or the color change was skipped.
2 — Average A real gap: the rings pile up in one spot (pivot or frameRot wrong), the base is missing, or the basket is built from copied ring blocks instead of a loop.
1 — Below Average Only one ring draws, or the program doesn't produce a recognizable basket when Play is pressed.
0 — Failing No Basket design in your Tinkercad account, or nothing drawn at all.