Hi plottingmad! Yes, the vast majority of the code in most drawbots is to handle the command protocol rather than the actual drawing mechanics. That's the good news, because it really means that the actual drawing mechanics are pretty small and simple.
This code that formed the AS220 machine (https://web.archive.org/web/20090522073800/http://www.as220.org:80/labs/Code/drawbotErikSatie.txt) was the first I saw with source attached. Some of this still lives on inside Polargraph actually - spiral pixel uses these curve routines.
It's reasonably understandable on it's own, and it's about as stripped back as you'll get I think, there's no comms or commands as such.
In Polargraph, look in the util.ino file for the kinematics - there's a couple of functions in there:
float getMachineA(float cX, float cY)
{
float a = sqrt(sq(cX)+sq(cY));
return a;
}
float getMachineB(float cX, float cY)
{
float b = sqrt(sq((pageWidth)-cX)+sq(cY));
return b;
}
https://github.com/euphy/polargraph_server_a1/blob/master/util.ino#L165-L174
Given a cartesian x and y, these two above work out the length of cord A and cord B, ie the distance to the top left and right corners of the surface.
long getCartesianX(float aPos, float bPos)
{
long calcX = long((pow(pageWidth, 2) - pow(bPos, 2) + pow(aPos, 2)) / (pageWidth*2));
return calcX;
}
long getCartesianY(long cX, float aPos) {
long calcY = long(sqrt(pow(aPos,2)-pow(cX,2)));
return calcY;
}
https://github.com/euphy/polargraph_server_a1/blob/master/util.ino#L225-L242
The two above do it in the opposite way, converting the native machine coordinates (distance from the top corners) into cartesian coordinates. Note that you need to work out the cartesian X first, and use it as a parameter to work out the Y.
sn
|