Drawing An Interesting Line

This class, we're drawing an interesting line.

The Engineering Part

You are going to be creating a line as a text file that looks like this example.pat file:


In other words, most lines contains a line number, command, X coordinate, and Y coordinate:


This happens to be exactly the pattern format required by our large CNC sewing machine's control software, and is a subset of the G-code language. The strange-seeming restrictions on line numbers and number formats are included because the machine control software's G-code interpreter is prone to errors, and we have found that this subset works. (You can actually use a few other G commands, including circular arcs, but this is not relevant to our current situation.)

The Artful Part

Of course, many lines are not particularly interesting. But what does it mean for a line to be interesting? That's up to you to decide; but make sure you do decide, so that you will be able to subjectively evaluate your success.

What To Do

This viewer can be used to check that your .pat file is in the proper format.

You may find this svg2pat.py python script (part of the pat-tools repository) to be helpful; either because you want to create your line by drawing an SVG file (perhaps by hand), or as code reference. Beware that this script outputs exactly what's in the svg file; so you need to make sure your file contains a single <path> containing a single continuous line.

Helpful Code and Notes

Whether you write code or try to use the svg2pat.py script, make sure that you test that the engineering part of the exercise is working ASAP.

If writing a .pat file from python, you will need to open your file in 'binary mode' in order to write the '\r\n' line ending properly:

f = open('out.pat', 'wb')

Rounding to exactly three decimal places can be tricky:

command = "N{}G01X{:.3f}Y{:.3f}".format(
	round(X * 1000.0) / 1000.0,
	round(Y * 1000.0) / 1000.0
command = "N" + lineNumber.toString() + "G01" + "X" + X.toFixed(3) + "Y" + Y.toFixed(3);