Hey Olly - good to see your page! Jumping straight into cmyk is impressive - and pretty decent results too. I guess your input "image" is still an upside down thing, with the detail turned 45 degrees though? I wasn't quite clear how it was generated from the page.
I think your issue is that you are treating the polar grid as if it simply a rotated version of a cartesian grid, and it isn't, almost at all. A 45 degree rotate will work for a couple of pixels out of each drawing, but the rest will be off, potentially by miles, primarily because the polargraph's axes are both curved - there are no straight lines in there at all. The angles of intersections of each axis line (each concentric circle) is almost never 90 degrees, so any system that maps a set of pixels from a cartesian coordinates system will be very distorted. The fact that pixels are tall and narrow at the top of the drawing surface, and short and fat at the bottom, is evidence of that.
The solution is re-rasterisation. That's essentially what the polargraph controller software does. Create a bunch of circles emanating from each of the motor points, then compile a list of coordinates of all the places that the circles intersect. For each point of intersection, work out the cartesian position on the desired image, and pull out a brightness value from the pixel at those coordinates.
A 2D array does not have to have every row the same length, but you do need to know the size of it beforehand so you can declare it, so that limits it's usefulness. I don't ever do any array handling in the arduino code - it is so much easier to do that stuff with hashmaps and lists in Processing.
The norwegian pixel re-rasterises an input file in the arduino though, so you could have a look at that - https://github.com/euphy/polargraph_server_mega/blob/master/rove.ino
Basically the same thing, except it doesn't compile a big list of pixels before it starts drawing - it essentially moves the pen to a certain spot on the surface, and knowing where the image is, and what size it is supposed to be, it works out the position of the pen over the image, then pulls out the pixel (density), and does a squiggle based on that density. Because memory is limited on the arduino, it never stores info before or afterwards, but then I do have the luxury of having an SD card with the image file on it.
Overall, if you are thinking of any linear transformation or translation between a cartesian bitmap and the native "polargraph" coordinates, then you will always have very bendy images. Bite the bullet and break out the pythagoras 🙂
good luck!
sn
|