Chapter 1
Getting started
knotflow describes a model as text: a few lines that say what it is made of and what its sizes depend on. Change a number, and the whole model is made anew. The result is a file for the 3D printer (STL or 3MF) or a picture.
This chapter shows the way from the first model to the file for the printer. Some programming experience helps, but is not needed.
In the browser
The quickest way needs no installation: fliegendreck.codefloe.page/knotflow.
- On the left is the text of the model, on the right the view. Dragging turns the view, the mouse wheel zooms.
- Model at the top picks one of the examples. Each shows one technique; together they are a good overview of what can be done.
- Lines that start with
paramappear as sliders in the view. Drag one, and the model is computed again at once; the new number then stands in the text as well. - save STL and save 3MF download the model. You open the file in the slicer, the program that cuts a model into layers for the 3D printer and turns them into the printer's moves. 3MF keeps the colours and the separate parts.
- Changes to the text stay saved in the browser. reset brings back an example's original, also its changed or deleted libraries; the question before names them.
A model of your own is started under Project → Open folder
… (Chrome and Edge): the browser then reads and writes the
.kf files directly in that folder. So you can work on them
in another editor at the same time. Other browsers have Download
as ZIP.
The first model
// A twisted vase of hexagons
param height = 120 in 40..300 "height [mm]"
param radius = 40 in 20..100 "radius [mm]"
param twist = 60 in 0..180 "twist at the top [°]"
fn ring(t) = polygon(6, radius * (1 - 0.3 * t)) |> rotate(t * twist) |> move(z: t * height)
export loft([ring(t) | t <- linspace(0, 1, 8)], degree: 3)
Line by line:
//starts a comment: the rest of the line is a note for people, knotflow skips it. Longer comments stand between/*and*/.paramsets a number that can be changed from outside: a name, the default value, the range for the slider and a description.fn ring(t) = …is a function. For t from 0 to 1 it gives a hexagon that gets smaller towards the top, turns and moves up.|>hands the result on to the next step: first the hexagon, then turn it, then move it.[ring(t) | t <- linspace(0, 1, 8)]is a list: eight rings for eight evenly spaced values of t.loftspans a surface through the rings, andexportsays that it belongs to the model. A closed surface becomes a solid; open ends get flat caps.
All sizes are millimetres, all angles degrees.
Errors
An error is underlined red in the text; below it stands what is
wrong, usually with a hint how it was meant. Write x ** 2
as in Python, for instance, and knotflow says: "powers are written with
^: 2 ^ 3". The messages are in English, like the names of the
functions.
On your own computer
Everything the browser does, kf, the command-line
program, does as well:
kf render vase.kf -o vase.stl
It is worth it if you want to work in your own editor, compute many
models at once or teach the language to an AI assistant. Chapter 2 shows
how to install kf and everything it can do.
What comes next
- Chapter 2 shows
kf, the language server in the editor and the tools for AI assistants. - Chapter 3 sums up the language: values, functions,
lists, records,
match. - Chapter 4 computes with numbers, points and curves.
- Chapters 5 to 12 go by task: shapes, vessels, combining solids, rounded edges, constructing measures from conditions, patterns, text and pictures, organic forms.
- Chapter 13 is about printing: tolerance, preview, STL and 3MF.
If you want to understand how knotflow works inside (NURBS, the interpreter, Boolean operations), you will find it in the lessons.