注意:该中文文档为社区驱动的非官网文档,可能存在错译、漏译或过时等问题,请以官网文档 Documentation 为准,如发现错漏,也欢迎 您的贡献镜像)。Typst 非官方中文交流 QQ 群:793548390
Warning: the Chinese document is a community-driven non-official document, there may be mistranslation, omission or outdated problems, please refer to the official website documentation.
Typst 中文文档

polygon 元素
元素函数可以通过 set 和 show 规则进行样式自定义。

A closed polygon.

The polygon is defined by its corner points and is closed automatically.

Example

#polygon(
  fill: blue.lighten(80%),
  stroke: blue,
  (20%, 0pt),
  (60%, 0pt),
  (80%, 2cm),
  (0%,  2cm),
)
Preview

参数
参数是函数的输入,它们在函数名称后面的括号中传入。

fill
none color gradient pattern
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

How to fill the polygon.

When setting a fill, the default stroke disappears. To create a rectangle with both fill and stroke, you have to configure both.

Currently all polygons are filled according to the non-zero winding rule.

默认:none

stroke
none auto length color gradient stroke pattern dictionary
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

How to stroke the polygon. This can be:

Can be set to none to disable the stroke or to auto for a stroke of 1pt black if and if only if no fill is given.

默认:auto

vertices
array
必需参数位置参数
位置参数按顺序传入,不带名称。
可变参数
可变参数可以多次传入。

The vertices of the polygon. Each point is specified as an array of two relative lengths.

定义
函数和类型可以有与其关联的定义 (成员或方法)。可以使用 "." 操作符来访问调用它们。

regular

A regular polygon, defined by its size and number of vertices.

查看示例
#polygon.regular(
  fill: blue.lighten(80%),
  stroke: blue,
  size: 30pt,
  vertices: 3,
)
Preview

fill

How to fill the polygon. See the general polygon's documentation for more details.

stroke

How to stroke the polygon. See the general polygon's documentation for more details.

size

The diameter of the circumcircle of the regular polygon.

默认:1em

vertices
int

The number of vertices in the polygon.

默认:3