Codeblocks studio

Pick a seed, change its rules, then add your own operators. Each program line makes a shape or changes the settings for the shapes below it. The whole program repeats with i starting at 0.

Drag to orbit · scroll to zoom · grid = 10 mm

How the language works · operator reference

box x y z width depth height tilt orbit lean hue creates a box. Use sphere for an ellipsoid or cylinder for a cylinder. Positions and dimensions are millimeters; angles are degrees; hue is a color angle (0 red, 120 green, 240 blue). Z points up. Orbit turns both the shape and its position around the vertical axis.

move x y z, rotate x y z, scale x y z, and color hue set transformations for subsequent shapes, until replaced. These settings reset at each repeat. Rotate changes local orientation; orbit in a shape line turns its placement around the origin. Each shape is scaled, rotated locally, orbited, then moved.

Use i count twist rise radius size and arithmetic + - * / ( ) in any value. Keep each expression together without spaces: i*rise or (radius+size)/2. Create a named value with let angle i*twist, then use angle in shape values. change angle 5 adds 5 to it. Named values reset each repeat. Lines starting with # are comments. Repeat count comes from the control below; Step repeat reveals one loop at a time. This language is local to this studio and cannot be pasted into Tinkercad.

Try a mutation: set twist to 137.5°, make rise negative, swap a box for a sphere, or add a second shape. Intersections and floating parts are allowed here. This studio explores geometry; use a CAD tool and slicer to prepare a printable solid. Save your program to keep it or share it.

3D Design · Parametric CAD · Coding

Lesson · Imagine, Program, Make

Variables Loops Extrude Print-flat Fidgets

Start with an idea: a spiraling sculpture, a strange building, a flower, or something nobody has named yet. Compose shapes and transformations, use a loop to grow your design, and change its rules live. The experimental studio uses a small classroom language; rebuild your favorite ideas with Tinkercad’s blocks. Then try the checked ring-printing challenge below.

Why Design with Code?

A fidget needs more than an attractive model. Every ring needs a real hole, a sturdy wall, a flat first layer, and space between neighboring parts. Code lets us express those rules once and check every ring.

Here, step = wall + gap. Build from the outside inward, reducing the radius by that step each time. More rings use the same rule; changing a dimension updates both the model and the recipe.

Key idea: a parameter is a number your design depends on. A parametric design is one where you can change the parameters and get a correct new design, without redrawing anything.

Three Ideas: Variables, Loops, Extrude

1 · Variables: names for numbers

A variable is a labelled box holding a number. In Codeblocks use Create variable to name and initialize radius, then Change variable to update it. Any shape block can use the variable instead of a typed number, so when the variable changes, every shape that uses it changes too.

2 · Loops: do it again, a little differently

A loop repeats the blocks inside it. Repeat 10 times does the same thing ten times. Count with i from 1 to 10 also hands you a counter, i, that goes up each time, so each repeat can be different: move up by i × height, or shrink by i × 2 mm. One loop and a counter can place a hundred shapes.

3 · Extrude: from a flat outline to a solid

Many 3D shapes can be understood as a flat 2D outline that is pushed straight up to a height. That push is called an extrusion. A circle extruded becomes a cylinder. A ring (a circle with a smaller circle cut out of it) extruded becomes a tube. In Codeblocks you don't press an Extrude button; a shape's height setting is its extrusion. Change the height and the same outline grows taller or flatter.

Fidget Lab · nested rings

Choose a starting recipe, then adjust the dimensions. All rings sit on the bed at z = 0, with straight vertical walls and open space between them. Orbit the 3D model to inspect the walls, or use the top view to check the gaps. This is a geometry preview, not a motion or slicer simulation.

Import or transcribe? Download STL for a slicer or Tinkercad → 3D Designs → Import (millimeters, 100% scale). That imports a mesh, not code. For editable Codeblocks, manually drag the blocks in the recipe below. The text download is a transcription checklist; it is not an importable Codeblocks file or pasteable program.
Codeblocks studioChange a number. Watch the loop rebuild.

Drag to orbit · scroll to zoom · grid squares = 10 mm

01 / Block recipeRead from top to bottom

    Expected dimensions · millimeters
    Ring (outside → inside)Outer diameterHole diameterBottom / top z
    Validation level: dimensions and exported mesh are checked digitally. These presets have not been physically test-printed here. A green check means the lesson’s geometry rules passed; it does not certify your printer, filament, or slicer settings.

    Transcribe the Codeblocks exactly

    Open Tinkercad Codeblocks and start an empty design. Use millimeters. The colored recipe above is in execution order; every indented row belongs inside Repeat. Numbers update when you move the sliders. Text in a white slot is either a literal number or the named variable shown.

    1. Data: drag Create variable, name it radius, and enter the displayed outer radius as its initial value.
    2. Control: add Repeat with the displayed ring count. Put all remaining recipe blocks inside it.
    3. Shapes: add a Cylinder, selecting the solid swatch. Expand its settings: Radius = the radius variable, H = the displayed height, Sides = 64, Edge = 0, Edge Steps = 1. Add Move: x = 0, y = 0, z = height ÷ 2 (the recipe gives this as a number).
    4. Add another Cylinder, selecting the striped hole swatch. Radius takes a Math subtraction block: radius − wall (use the numeric wall value shown). H = height + 2, Sides = 64, Edge = 0, Edge Steps = 1. Add its own Move: x = 0, y = 0, z = height ÷ 2. The hole extends 1 mm beyond both faces.
    5. Modify: add Create Group to combine all shapes created so far and subtract the hole. Use the group-all operation, rather than grouping only the last selected shape. Do this inside the repeat. Each smaller hole stays entirely inside the earlier ring’s opening, so it cannot erase an earlier ring.
    6. Data: add Change variable, choose radius, and enter the negative step shown: −(wall + gap). The recipe supplies the calculated number. This is the last block inside Repeat.
    7. Run, then compare the outer and hole diameters with the table above. Codeblocks cylinders are centered on their origin: moving by half the height places their bottom at z = 0. If your result sits below the grid, check those Move blocks. Export STL, open it in a slicer, and compare the piece count and overall size before printing.

    Do not reverse the loop. Building from small to large with group-all subtraction would cut away the rings already made. Do not add a base or scale the finished fidget: a base joins the pieces, and scaling changes the clearance.

    Block and coordinate references: Mike Bailey’s Codeblocks teaching slides and Code Club Australia’s cylinder/hole fidget tutorial. The nested-ring dimensions and checks on this page are classroom designs.

    Before printing · check the fit

    1. Print the clearance test first. Two rings, 28 mm across, 2 mm high, with the same 0.6 mm radial gap as both presets. After cooling, they should lift apart without cutting. If fused, resolve first-layer squish / elephant’s foot or increase the gap and retest.
    2. Starting setup: PLA, 0.4 mm nozzle, 0.2 mm layers, 3 perimeters, and your printer’s normal PLA profile. Lay the rings flat. No supports, raft, or brim connecting neighboring rings. These are starting settings, not a printer-specific guarantee.
    3. Inspect the sliced layers. Expect one disconnected closed ring per table row, an empty central opening, and a visible gap between rings on every layer including the first. Overall width = 2 × outer radius. Stop if the slicer reports mesh repair, fills the holes, or bridges the gaps.
    4. Cool and inspect. Remove burrs and sharp edges before use. These loose parts are classroom manipulatives; keep them away from children who mouth objects. Do not force a ring onto a finger.
    Gap is radial. A 0.6 mm gap means the next outer diameter is 1.2 mm smaller than its neighbor’s hole diameter. All cylinders use the same 64 sides and orientation. The check also accounts for the slightly narrower gap at polygon edges.

    Ring volume is π(R² − r²) × h, where r = R − wall. The readout estimates the fully solid model’s volume and PLA mass (1.24 g/cm³); slicer infill, perimeters, and extrusion settings determine actual filament use. See 3D Printing for slicing and Pi for the circle math.

    Codeblocks wordWhat it means
    VariableA named number the program can read and change
    Loop / Count withRepeat blocks, with a counter i that changes each time
    ParameterA number the whole design depends on
    ExtrudePush a flat outline up to a height to make a solid
    HoleA shape that cuts away whatever it's grouped with

    Practice Problems

    Easy1. A loop runs Count with i from 1 to 6. How many rings does it make?

    Hint: i takes the values 1, 2, 3, …

    Easy2. Pushing a flat outline straight up to a height to make a solid is called…

    Hint: Toothpaste squeezed from a tube keeps its outline as it gets longer.

    Medium3. A cylinder is centered on z = 0 and is 4 mm high. How far up (mm) must Move shift it so the bottom rests on the bed?

    Hint: Half the height starts below the bed; shift up by height ÷ 2.

    Medium4. Radius starts at 30 mm and changes by −3 each loop. What is the radius of ring 5?

    Hint: Ring 1 is 30. The change happens after each ring, so ring 5 has had 4 changes.

    Medium5. What is the circumference of a 20 mm radius ring, to the nearest mm?

    Hint: C = 2 × π × 20.

    Challenge6. With a 3 mm wall and a 0.6 mm gap, what signed value should Change variable radius use to build inward?

    Hint: Subtract wall + gap: −(3 + 0.6).

    Challenge7. What makes a design parametric?

    Hint: Think about what happened when you moved the rings slider.

    Next: build a moving part in Print Fidgets, or try parametric parts in Forge and free-form building in Workbench.