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
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.
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.
Drag to orbit · scroll to zoom · grid squares = 10 mm
| Ring (outside → inside) | Outer diameter | Hole diameter | Bottom / top z |
|---|
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.
- Data: drag Create variable, name it
radius, and enter the displayed outer radius as its initial value. - Control: add Repeat with the displayed ring count. Put all remaining recipe blocks inside it.
- Shapes: add a Cylinder, selecting the solid swatch. Expand its settings: Radius = the
radiusvariable, 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). - 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. - 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.
- 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. - 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
- 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.
- 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.
- 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.
- 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.
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 word | What it means |
|---|---|
| Variable | A named number the program can read and change |
| Loop / Count with | Repeat blocks, with a counter i that changes each time |
| Parameter | A number the whole design depends on |
| Extrude | Push a flat outline up to a height to make a solid |
| Hole | A 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?
Easy2. Pushing a flat outline straight up to a height to make a solid is called…
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?
Medium4. Radius starts at 30 mm and changes by −3 each loop. What is the radius of ring 5?
Medium5. What is the circumference of a 20 mm radius ring, to the nearest mm?
Challenge6. With a 3 mm wall and a 0.6 mm gap, what signed value should Change variable radius use to build inward?
Challenge7. What makes a design parametric?
Next: build a moving part in Print Fidgets, or try parametric parts in Forge and free-form building in Workbench.