Kinematic 0.5.0 is out. Modeling and sculpting in the viewport, a timeline on every graph, photo and sound editing. What's new
Kinematic / Learn / Develop / Spin a donut with one line of Python
Develop tutorial

Spin a donut with one line of Python

Tutorial8 minFirst steps8 stepsStarts from a new project
What you will make

An orange donut that tumbles end over end and breathes in and out, moved by two short Python expressions typed straight into its settings.

The donut a moment apart: each line of Python turns it and swells it as the seconds go by.
The donut a moment apart: each line of Python turns it and swells it as the seconds go by.

Any number in Properties can follow a line of Python instead of holding still. Kinematic runs the line again on every frame, and t is the time in seconds since the graph started playing.

Steps

  1. Click New Project. On the start card, click Add a shape and pick Torus. A donut lands in the middle of the view.

  2. Give it a color. Open Surface > Material > New PBR material. In the Objects panel, under Materials, click Torus 1 material. In Properties, click the hex box beside Base color, type #E8833A and press Enter.

    The donut with its new material, and Torus 1 material listed under Materials.
    The donut with its new material, and Torus 1 material listed under Materials.
  3. Click Torus 1 in the Objects panel so Properties shows the donut. Under Configuration, type turn in the filter box. Turn X, Turn Y and Turn Z are left.

  4. Right-click Turn X and choose Set Python Driver (@). The Driver Editor opens in Python mode, with t already in the Expression box.

    Right-click a setting for its driver choices. Set Python Driver (@) is the second one.
    Right-click a setting for its driver choices. Set Python Driver (@) is the second one.
  5. Replace t with this line and click OK:

    python
    (t * 90) % 360

    The donut tumbles a quarter turn every second. The % 360 wraps the angle back to 0 after a full turn, because Turn X takes values from -360 to 360.

    The Driver Editor in Python mode. It checks the line as you type and shows the value it gives right now.
    The Driver Editor in Python mode. It checks the line as you type and shows the value it gives right now.
  6. Look at Turn X in Properties. It now shows the value changing live, the line it follows, and a small graph of the last few seconds.

    Turn X follows the Python line. Turn Y and Turn Z still hold plain numbers.
    Turn X follows the Python line. Turn Y and Turn Z still hold plain numbers.
  7. Make it breathe. Type uniform in the filter box, right-click Uniform scale, choose Set Python Driver (@), and replace t with:

    python
    1 + 0.2 * sin(t * 4)

    Click OK. The donut swells and shrinks a little, about every second and a half.

    Uniform scale follows a sine wave between 0.8 and 1.2.
    Uniform scale follows a sine wave between 0.8 and 1.2.
  8. Hover over the viewport and press Shift+H to hide the handles, then watch it move. Save with File > Save.

On the canvas

The steps added a 3DGeoTorus for the donut and a PbrMaterial that a 3DGeoSetMaterial puts on it. The two Python lines live on the torus itself, as the values of its turn and size settings.

Make it yours

  • Bob it up and down: filter for move, right-click Move Y and set its Python driver to 0.5 * abs(sin(t * 3)).
  • Add a second turn with Turn Y set to (t * 40) % 360, so it wobbles as it tumbles.
  • Slow it down: (t * 30) % 360 turns it once every twelve seconds.
  • math is ready to use in any line, so math.floor(t) * 45 % 360 turns the donut in steps, once a second.

If it goes wrong

  • The editor says the line is not valid: check the brackets, and use t (not time) for the seconds.
  • To go back to a plain number, right-click the setting and choose Set Constant Value.
Keep going

Free and open. Yours, forever.

No account, no license key. macOS, Windows, Linux and Raspberry Pi.

Download for macOS 0.5.0