Laser Cutting with Python
Wouldn't it be cool that apart from making apps, you can also produce physical things with your coding skills?
This basic tutorial will show you how you can use the Python Turtle library to create shapes ready for laser cutting! The concept is the same for any language, I'm using Python because lots of students use it in the UK.
Create a shape with the Turtle library
The Turtle library comes installed with Python, so you don't need to worry about installing it.
# import everything in the library from turtle import * # move forwards 100 pixels forward(100) # finish done()
Run your program, and you should see a line being drawn. The picture above is a necklace made by analyzing a sound file. After processing the .wav file, I needed to create a whole lot of circles. There are many primitive shapes you can use in the library — here're the docs.
Export the design
After you've done your design, the key part is exporting in a format suitable for the laser cutter. Fortunately, the canvas that the Turtle library uses can easily export to PostScript!
At the end of your program (but before the
done()), add these lines:
# hide the little turtle icon so it doesn't get exported hideturtle() # export the drawing as a postscript file getscreen().getcanvas().postscript(file="circles.eps")
This will create a PostScript file in the current directory called
I use Corel Draw with my laser cutter, and it imports these files perfectly. I've also found SVGs to work well and there are lots of libraries for all languages you can use. An issue to watch out for is scaling, create a 100mm line somewhere and use it as a reference.
I developed the waveform necklace as a way of making programming applied and fun. More information about processing the wave files and creating lots of circles is in the github repo here.