PhiL and tf - thank you for your suggestions! I ended up not using either because:
a) I want the curve shape to be a direct representation of a plot from a data file, which is possible with PhiL's approach, but somewhat masked. I opted to maintain the curveVertex approach so that the plotting of individual data points was transparent in the code.
b) I want my code to be portable, documented, and stable (though I do love finding out about features in testing, so thank you tf!)
I ended up coming up with the following approach, which I wanted to share in case anyone else has a similar type of project:
(pseudocode):
- float x, y;
- int torWidth = 10;
- fill(bgColor);
- beginShape();
- // Draw outer edge of donut
- for (int i = 0; i < ptsInCircle; i++){
- //...compute r, theta...
- x = r*cos(theta);
- y = r*sin(theta);
- curveVertex(x,y);
- }
- // trace inner edge of donut, in OPPOSITE direction
- for (int i = ptsInCircle-1; i >= 0 ; i--){
- //...compute r, theta...
- x = (r-torWidth)*cos(theta);
- y = (r-torWidth)*sin(theta);
- curveVertex(x,y);
- }
- endShape();
This ended up doing exactly what I wanted it to. The trick which took me a while to realize is that for continuous 2D shapes like this, the two curve shapes (inner and outer) have to be going in opposite directions for the fill to behave properly.
Thanks again for the help!