Skip to content

ROUNDPOLYGON ​

Draws a closed shape with rounded corners by connecting several points.

Syntax ​

leo-grammar
ROUNDPOLYGON arrayValue [ r:measureValue ] .

Parameters ​

  • <main-parameter> (arrayValue) - Used in the array version to specify the points. The array must have an even amount of measure values.
  • r (measureValue, optional) - The radius to use for rounding corners. The default is 0cm.

Details ​

The style of this command is defined by the PEN command for the outline and the FILL command to fill the shape.

The amount of values in the array specified as the <main-parameters> must be an equal number and all values must be a measureValue. The first two values are used as the x- and y-coordinate of the first point, the next two values as the x- and y-coordinate of the second point and so on.

The benefit of using an array for the points is that it doesn't require to specify the amount of points upfront. Instead they are determined based on the array's length. This way other commands can be used to build the array dynamically.

This command extends upon POLYGON by drawing all corners of the shape rounded. However, the points must always be specified using an array. The amount of values in the array must be an equal number and all values must be a measureValue. The first two values are used as the x- and y-coordinate of the first point, the next two values as the x- and y-coordinate of the second point and so on.

This command differs from POLYLINE in that it connects the last point back to the first, creating a closed shape that can be filled with a color. The lines of the polygon can intersect, in which case the area that is considered part of the shape depends on the sequence in which the points are connected.

See Also ​

Examples ​

Draw a triangle with rounded corners.
A triangle with rounded corners

leo
GRAPHREP
SHADOW off

ROUNDPOLYGON {-0.5cm, 0.5cm, 0cm, -0.5cm, 0.5cm, 0.5cm} r:0.2cm

Draw a purple hour-glass shape and a lying hour-glass shape to the right of it, both with rounded corners. The order of the points influences which areas are filled as part of the shape.
A purple hour-glass shape and a lying hour-glass shape to the right of it, both with rounded corners

leo
GRAPHREP
SHADOW off

FILL color:"purple"
# 1st: top-left, 2nd: top-right, 3rd: bottom-left, 4th: bottom-right.
ROUNDPOLYGON {-0.5cm, -0.5cm, 0.5cm, -0.5cm, -0.5cm, 0.5cm, 0.5cm, 0.5cm} r:0.3cm

# A different order of the points causes different areas to be filled in.
# 1st: top-left, 2nd: bottom-left, 3rd: top-right, 4th: bottom-right.
ROUNDPOLYGON {0.6cm, -0.5cm, 0.6cm, 0.5cm, 1.6cm, -0.5cm, 1.6cm, 0.5cm} r:0.15cm

Draw a green zig-zag shape with slightly rounded corners based on dynamically calculated points.
A triangular wavy line with rounded corners

leo
GRAPHREP
SHADOW off

# Configuration parameters.
SET dX:(0cm) dStartY:(0cm)
SET dW:(0.3cm) dH:(0.5cm)
SET nPoints:(7)
# Create array with a starting point.
SET aPattern:({dX, dStartY})
# `to` uses -2 because the first point has been added and the last point will be added later.
FOR nI from:(0) to:(nPoints - 2) {
  SET dX:(dX + cond(nI, dW, dW/2))
  SET dummy:(aappend(aPattern, dX))
  SET dummy:(aappend(aPattern, dStartY + cond(nI MOD 2, dH, -dH)))
}
# Addint the last point in the array.
SET dummy:(aappend(aPattern, dX + dW/2))
SET dummy:(aappend(aPattern, dStartY))

# Draw the shape, filling it with a green color.
FILL color:"chartreuse"
ROUNDPOLYGON (aPattern) r:0.1cm

Versions and Changes ​

Available since ADOxx 1.5