The ‘star’ element defines a regular non-convex star polygon. ‘Star polygons can be configured to create star shapes such as pentagrams, as well as regular polygons. The exact polygon shape produced depends on the center point, two radii, the number of vertices, the density and the type. The untransformed polygon will always, by default, have one of the vertices pointing northwards (negative y).
Attribute definitions:
Name | Value | Lacuna value | Animatable |
---|---|---|---|
cx, cy | <length> | 0 | yes |
Name | Value | Lacuna value | Animatable |
---|---|---|---|
rx, ry | <length> | 0 | yes |
Name | Value | Lacuna value | Animatable |
---|---|---|---|
points | <integer> | 0 | yes |
Name | Value | Lacuna value | Animatable |
---|---|---|---|
density | <integer> | 1 | yes |
Name | Value | Lacuna value | Animatable |
---|---|---|---|
type | normal | boundary | normal | yes |
The ‘type’ attribute defines whether the stroke of the shape is self intersecting, or rendered so that only the boundary line segments are visible. Values have the following meanings:
The stroke of a ‘star’ element begins at the "12 o'clock" point on the shape and progresses clockwise until it eventually returns to the start point. Some combinations of ‘points’ and ‘density’ will result in two or more subshapes. For example, the two triangles in a sixpointed star with a ‘density’ of "2". The starting point and direction of the stroke are affected by the user space transform in the same manner as the geometry of the element.
Example star01 below specifies
the coordinates of the two stars in the user coordinate system
established by the ‘viewBox’ attribute on the ‘svg’
element and the ‘transform
’ property on the ‘g’ and
‘star’ elements. Both stars use the default values of
zero for the ‘cx’ and ‘cy’ attributes (the center of the
star). The second star is rotated.
<?xml version="1.0" standalone="no"?> <svg width="12cm" height="4cm" viewBox="0 0 1200 400" xmlns="http://www.w3.org/2000/svg" version="1.1"> <desc>Example star01 - examples of stars</desc> <!-- Show outline of canvas using 'rect' element --> <rect x="1" y="1" width="1198" height="398" fill="none" stroke="blue" stroke-width="2" /> <g transform="translate(300 200)"> <star rx="250" ry="100" points="5" fill="red" /> </g> <star transform="translate(900 200) rotate(-30)" rx="250" ry="100" points="5" type="boundary" fill="none" stroke="blue" stroke-width="20" /> </svg>
Example star02 demonstrates the effect that changing the ‘points’ and ‘density’ attributes has on the shape. All the shapes in this example have the ‘type’ set to "normal".
<?xml version="1.0" standalone="no"?> <svg width="12cm" height="12cm" viewBox="0 0 1050 1050" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script type="text/javascript" xlink:href="star.js" /> <desc>Example star02 - examples of stars of normal type</desc> <!-- Show outline of canvas using 'rect' element --> <rect x="1" y="1" width="1048" height="1048" fill="none" stroke="blue" stroke-width="2" /> <g stroke-width="16" fill="none"> <star cx="150" cy="150" rx="100" ry="100" points="3" stroke="blue" /> <star cx="400" cy="150" rx="100" ry="100" points="4" stroke="green" /> <star cx="650" cy="150" rx="100" ry="100" points="5" stroke="orange" /> <star cx="900" cy="150" rx="100" ry="100" points="5" density="2" stroke="orange" /> <star cx="150" cy="400" rx="100" ry="100" points="6" stroke="red" /> <star cx="400" cy="400" rx="100" ry="100" points="6" density="2" stroke="red" /> <star cx="650" cy="400" rx="100" ry="100" points="7" stroke="cyan" /> <star cx="900" cy="400" rx="100" ry="100" points="7" density="2" stroke="cyan" /> <star cx="150" cy="650" rx="100" ry="100" points="8" stroke="purple" /> <star cx="400" cy="650" rx="100" ry="100" points="8" density="2" stroke="purple" /> <star cx="650" cy="650" rx="100" ry="100" points="8" density="3" stroke="purple" /> <star cx="900" cy="650" rx="100" ry="100" points="7" density="3" stroke="cyan" /> <star cx="150" cy="900" rx="100" ry="100" points="9" stroke="olive" /> <star cx="400" cy="900" rx="100" ry="100" points="9" density="2" stroke="olive" /> <star cx="650" cy="900" rx="100" ry="100" points="9" density="3" stroke="olive" /> <star cx="900" cy="900" rx="100" ry="100" points="9" density="4" stroke="olive" /> </g> </svg>
Example star03 demonstrates the effect that changing the ‘type’ to "boundary" has on the above example.
<?xml version="1.0" standalone="no"?> <svg width="12cm" height="12cm" viewBox="0 0 1050 1050" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script type="text/javascript" xlink:href="star.js" /> <desc>Example star03 - examples of stars of boundary type</desc> <!-- Show outline of canvas using 'rect' element --> <rect x="1" y="1" width="1048" height="1048" fill="none" stroke="blue" stroke-width="2" /> <g stroke-width="16" fill="none"> <star cx="150" cy="150" rx="100" ry="100" points="3" type="boundary" stroke="blue" /> <star cx="400" cy="150" rx="100" ry="100" points="4" type="boundary" stroke="green" /> <star cx="650" cy="150" rx="100" ry="100" points="5" type="boundary" stroke="orange" /> <star cx="900" cy="150" rx="100" ry="100" points="5" type="boundary" density="2" stroke="orange" /> <star cx="150" cy="400" rx="100" ry="100" points="6" type="boundary" stroke="red" /> <star cx="400" cy="400" rx="100" ry="100" points="6" type="boundary" density="2" stroke="red" /> <star cx="650" cy="400" rx="100" ry="100" points="7" type="boundary" stroke="cyan" /> <star cx="900" cy="400" rx="100" ry="100" points="7" type="boundary" density="2" stroke="cyan" /> <star cx="150" cy="650" rx="100" ry="100" points="8" type="boundary" stroke="purple" /> <star cx="400" cy="650" rx="100" ry="100" points="8" type="boundary" density="2" stroke="purple" /> <star cx="650" cy="650" rx="100" ry="100" points="8" type="boundary" density="3" stroke="purple" /> <star cx="900" cy="650" rx="100" ry="100" points="7" type="boundary" density="3" stroke="cyan" /> <star cx="150" cy="900" rx="100" ry="100" points="9" type="boundary" stroke="olive" /> <star cx="400" cy="900" rx="100" ry="100" points="9" type="boundary" density="2" stroke="olive" /> <star cx="650" cy="900" rx="100" ry="100" points="9" type="boundary" density="3" stroke="olive" /> <star cx="900" cy="900" rx="100" ry="100" points="9" type="boundary" density="4" stroke="olive" /> </g> </svg>