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 / Build a ring of spheres with a Python script
Develop tutorial

Build a ring of spheres with a Python script

Tutorial12 minGetting going7 stepsStarts from a new project
What you will make

Twelve teal spheres in a wavy ring, made by a short Python script that adds the nodes and wires them for you.

Twelve spheres around a wavy ring, every one of them placed by the script.
Twelve spheres around a wavy ring, every one of them placed by the script.

A script can do anything you can do with the mouse, many times over. This one adds twelve spheres, moves each one to its place on a circle and joins them into one object.

Steps

  1. Click New Project.

  2. Press Ctrl+Shift+E. The Python Script Editor opens in a window of its own.

    The Python Script Editor: the code at the top, Run and Debug in its menu, and the play button for Run Script.
    The Python Script Editor: the code at the top, Run and Debug in its menu, and the play button for Run Script.
  3. Click in the code, select all of it with Ctrl+A (Cmd+A on a Mac) and paste this script over it:

    python
    import math
    import kinematic.graph
    
    g = kinematic.graph.current()
    count = 12
    ring = g.create_node("3DGeoMerge", position=(800, 600), config={"num_inputs": count})
    
    for i in range(count):
        angle = i / count * math.tau
        ball = g.create_node("3DGeoSphere", position=(i % 2 * 320, i // 2 * 260), config={
            "radius": 0.2,
            "t_tx": math.cos(angle) * 1.5,
            "t_tz": math.sin(angle) * 1.5,
            "t_ty": math.sin(angle * 3) * 0.4,
        })
        g.connect(ball, "Geometry_Out", ring, f"Geometry_In_{i + 1}")
    
    print(f"Made {count} spheres and joined them in {ring.id}")
  4. Choose Run > Run Script, or press F5. The script adds a Merge node with twelve inputs, then twelve spheres. Each sphere gets a radius and a place on the circle (t_tx, t_tz and t_ty are its Move X, Move Z and Move Y), and each one is wired into the Merge.

  5. In the main window's Objects panel, click Merge 1. The viewport shows the whole ring, rising and falling three times as it goes around.

    Merge 1 holds all twelve spheres in the Objects panel.
    Merge 1 holds all twelve spheres in the Objects panel.
  6. Color it. Open Surface > Material > New PBR material. In the Objects panel, under Materials, click the new material, then in Properties click the hex box beside Base color, type #3FA7A0 and press Enter.

  7. Hover over the viewport and press Shift+H to hide the handles. Save with File > Save.

On the canvas

The script added a 3DGeoMerge and twelve 3DGeoSphere nodes, each wired into its own Merge input, and your color step added a PbrMaterial and a 3DGeoSetMaterial after the Merge. The position values in the script lay the spheres out in two neat columns.

Twelve Sphere nodes in two columns, every one wired into the Merge.
Twelve Sphere nodes in two columns, every one wired into the Merge.

Make it yours

  • Change count = 12 to 24 and "radius": 0.2 to 0.1, open a new tab with the + beside the tab name, and run the script there.
  • Change angle * 3 to angle * 5 for five waves around the ring.
  • Swap 3DGeoSphere for 3DGeoTorus, and "radius": 0.2 for "major_radius": 0.2, "minor_radius": 0.06, for a ring of rings.
  • Go further with Help > Python > Script Templates, which has worked examples to start from.

If it goes wrong

  • Nothing appears in the viewport: click Merge 1 in the Objects panel. The viewport shows the object you pick.
  • Running the script twice makes a second ring on top of the first. Start a new tab before you run it again.
Keep going

Free and open. Yours, forever.

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

Download for macOS 0.5.0