I want to draw some arbitrary curves, defined mathematically, e.g. sin(x), 1/x etc.
Is the a best way to use an open polygon or a series of points?
It would want to be drawn over time, rather then just dumped completed to the screen. Probably the crank will progressing it's drawing.
If each step that gets drawn is multiple pixels long, I'd probably use drawLine
? Either way, I'd draw wider than a single pixel, for visibility.
Is lines better than polygons?
I don't know your context, but if drawing just one line at a time, I'm not sure of the benefits of assembling a polygon.
If you're creating something for further manipulation, that might be different.
If you have a function that simply takes a time/crank-tick as an parameter, it can just return the next cartesian co-ordinate. I would store these points to an array as they are generated.
A separate function drawPolyLine
that takes this array of co-ordinates and uses playdate.graphics.drawLine(x1, y1, x2, y2) to plot the points. Whenever a new point arrives, draw the next bit.
If you read the definition for drawPolygon(), it's pretty close to drawing an a polyLine, except that there's an "extra" line from the end back to the start. As far as I'm aware, there's no polyLine drawing function already. But, I don't see how using polygon drawing helps.
Having the points stored in an array also allows the code to re-draw the graph at any time. Like when the entire screen needs to be repainted.
BTW: I found this repo about Lua polyLines (for Love, not PD) while searching for the Lua API. Maybe it's worth looking at for inspiration.