Rounded rectangle
in
Share your Work
•
2 years ago
I found a fairly efficient way to put together rounded rectangles, and I'm putting it here for future searchers as it seemed to be requested quite a bit on the original forum.
x,y is the top left corner, w,h is the width and height rx,ry are the radius for different axes of the rounded corners respectively. It could be made more efficient by avoiding repetition in the additions.
- void roundedRect(float x, float y, float w, float h, float rx, float ry)
- {
- beginShape();
- vertex(x,y+ry); //top of left side
- bezierVertex(x,y,x,y,x+rx,y); //top left corner
- vertex(x+w-rx,y); //right of top side
- bezierVertex(x+w,y,x+w,y,x+w,y+ry); //top right corner
- vertex(x+w,y+h-ry); //bottom of right side
- bezierVertex(x+w,y+h,x+w,y+h,x+w-rx,y+h); //bottom right corner
- vertex(x+rx,y+h); //left of bottom side
- bezierVertex(x,y+h,x,y+h,x,y+h-ry); //bottom left corner
- endShape(CLOSE);
- }
1