Archive | Uncategorized RSS feed for this section

Secret Round Rects

5 Jan

Did you know Processing has a secret feature to draw round rects, or rectangles with rounded corners? I say secret because the feature isn’t documented on the main reference page for the rect routine.

The JavaDoc page for PApplet, however, briefly mentions, without explaining, two alternate versions of the rect routine:

rect(float a, float b, float c, float d, float hr, float vr)

rect(float a, float b, float c, float d, float tl, float tr, float bl, float br)

Both of these routines draw rounded rectangles. In the first, you specify the horizontal and vertical radii of the corners, this allows you to have non-circular corners that are constructed from elliptical arcs. In the second version, which draws only circular corners, you specify the radius of each corner individually, starting with the top-left. You can use this second routine to create unusual shapes in which not all the corners are rounded.

This is one of a handful of hidden gems which can be found by taking a closer look at the Processing JavaDoc. I’ll highlight others in future posts.