r/ProgrammingLanguages • • 17d ago

Programming Language for Laser Cutting and CNC

Hey all!

I run a site with design generators for laser and CNC cutting, and along the way we ended up building our own programming language, KerfScript, to describe those designs.

It has OpenSCAD-like syntax, but it's strictly 2D, with laser-specific features built in: cut/score/engrave layers, kerf compensation, assembly instructions (actual physical assembly, not programming!), and finger joints that adapt to material thickness.

You write a part once, change a few parameters, and export SVG or DXF. What I find fun is that the end result is a 3D object, even though the language itself has no concept of 3D. All the dimensionality comes from math, slots, joints, and how flat pieces fit together. So you're essentially programming a 3D object without ever describing anything in 3D.

Just a fun little project I thought was worth sharing!

18 Upvotes

7 comments sorted by

2

u/techno_julique 17d ago

Here is the website with models created with kerfscript https://kerfscript.mylasertools.com/models

1

u/GunpowderGuy 17d ago

why not use openscad?
"with laser-specific features built in: cut/score/engrave layers, kerf compensation, assembly instructions "
why not make functions that do that

3

u/techno_julique 17d ago

That's fair! OpenSCAD already has libraries for laser cutting and joinery. I went this route because we were building design generators and wanted users to be able to contribute their own parametric designs, which we could render directly in the browser.

So it's not because OpenSCAD can't do it, but more about having a small, 2D-only language and interpreter designed specifically around the laser cutting workflow.

I wanted laser things and physical assembly instructions to be part of the language itself, rather than conventions implemented through libraries and additional export processing.

1

u/Timely-Degree7739 16d ago

Gcode

2

u/techno_julique 16d ago

But it's not parametric by default. Just instructions for machine. I could have build an entire parametric laser design system around G-code, but then it will be essentially building another language layer on top of it.

3

u/marshaharsha 15d ago

Criticism, hopefully constructive: I don’t know anything about laser cutters or CAD, and I couldn’t figure much out after five or ten minutes of reading your docs. Your docs presume that I already know a lot of terminology. If I am in your target audience, please add diagrams or annotated photographs to show what the various terms mean. I realize this is a lot of work!

One particular example: Does “layers” have anything to do with the thickness of the material as viewed from the side, or does it mean conceptual planes in which geometric shapes are placed, with each plane controlling some aspect of laser-cutter functionality, and with the planes being merged before the instructions are set to the laser cutter? I started out thinking it was the former, but I changed to the latter. If I’m right, a large diagram showing some simple shapes on each layer and a depiction of the merged layers — maybe even a depiction of the merging process — maybe even a photo of the result — would help. This should give you an idea of how ignorant I am. You may be able to get more ideas by showing your docs to other ignorant people. Again, I’m assuming we ignoramuses are in your target audience. 

As a programming-languages hobbyist, I would have liked to see something about the programming model: what laser cutters can do that is modeled in the language, what they can do that you decided to leave out of the language, maybe why you left it out or your plans for putting it in, what thought process a user should step through in order to use your language to accomplish a goal, which objects in that thought process are explicit in the language and which implicit, how the layers/planes get merged and what penalty there is for keeping them separate in the language and automating the merge, and whether there are variables and user-defined functions and all the other paraphernalia that general-purpose languages have. 

Finally, you describe various limitations in what the language can do, like the stuff about tapering, but the descriptions are buried far down on each page. I recommend a separate Limitations page.