Polygons
Arc
Arc([arc, radius, orbit], anchor?=, cap?, pos?, angle?) -> shape
Returns an arc Polygon. An arc is curved line that follows the edge of a circle. A bit like the letter C, a horseshoe or a rainbow.
This can be used by functions like PolygonCollider or PolygonSprite.
Size and Shape:
-
arc(Number): The angular width of the arc in radians. For example,0.25revwould make an arc that covered one quarter of a circle. -
orbit(Number): The distance of the arc from the focal point of the arc. A smaller number makes a tighter arc. -
radius(Number): The half-width of the arc. This controls the size the line itself. Ifradius >= orbit, then the arc becomes aSector.
Position and Rotation:
-
anchor(Number): If set to1(the default), the center of the arc's line will be placed at the origin. If set to0, the focal point of the arc will be placed at the origin. -
pos(Vector): Offsets the Arc from the origin by this amount. Defaults to@(0, 0). -
angle(Number): Rotates the Arc by this angle. For example,0.25revwould rotate the arc by a quarter turn. Defaults to0rev.
Style:
cap(Boolean): Whether the ends of the arc are rounded.
Capsule
Capsule([extent, radius], anchor?=, pos?, angle?) -> shape
Returns a capsule Polygon. A capsule is a single horizontal line segment with rounded ends. Like a pill or a sausage.
A capsule has two focal points, each in the center of its two rounded ends. By default, both focal points lie on the X-axis, with one on either side of the origin.
Size and Shape:
extent(Number): Defines the distance from the center of the capsule to the two focal points. In other words, defines the half-width of the capsule.radius(Number): Defines the distance from a focal point to the edge of the capsule. In other words, defines the half-height of the capsule.
Position and Rotation:
-
anchor(Number): A value between-1and1, where-1means the left end is placed on the origin, while1means the right end is placed on the origin.k Defaults to0, meaning the center of the capsule is placed at the origin. -
pos(Vector): Offsets the position of the capsule by the given vector. Defaults to@(0, 0). -
angle(Number): Rotates the capsule by the given angle in radians. For example,0.25revwould apply a quarter turn to the capsule. Defaults to0rev.
Circle
Circle([radius], pos?=) -> shape
Returns a circle Polygon.
radius(Number): The distance from the center of the circle to the edge of the circle.pos(Vector): Offsets the position of the circle. Defaults to@(0, 0).
Equilateral
Equilateral(numPoints, [radius], pos?=, angle?, border?) -> shape
Returns an equilateral Polygon. An equilateral polygon is a regular polygon with all sides and angles equal.
-
numPoints(Number): the number of points in the polygon, for example3for a triangle, or6for a hexagon. If it is less than 3, the polygon will be a circle. -
radius(Number): The distance from the center of the polygon its corner. -
pos(Vector): The position offset of the polygon. Defaults to@(0, 0). -
angle(Number): The angle of the polygon. For example,0.25revwould apply a quarter turn to the polygon. Defaults to0rev. -
border(Number): The width of the rounded border surrounding the polygon. Defaults to0.
Isosceles
Isosceles(base=, length, anchor?, pos?, angle?, border?) -> shape
Returns an isosceles triangle Polygon. An isosceles triangle is a triangle where two of the sides are of equal length. Like a guitar pick, a play button, or a triangular flag of bunting.
By default, the apex (or peak) of the isosceles points to the right. Because zero degrees also points to the right, this means by default, the isosceles points in the same direction as the heading of the body you attach it to. This makes it easy to use the isosceles to point at things.
Size and Shape:
-
base(Number): The length of the base of the triangle. -
length(Number): The distance between the base and the apex of the triangle. -
border(Number): The width of the rounded border surrounding the triangle. Defaults to0.
Position and Rotation:
-
anchor(Number): A value between-1and1, where-1means the base of the triangle is placed at the origin, while1means the apex of the triangle is placed at the origin. Defaults to0, meaning the middle of the triangle is placed at the origin. -
pos(Vector): The position offset of the triangle. Defaults to@(0, 0). -
angle(Number): The angle of the triangle. For example,0.25revwould apply a quarter turn to the polygon. Defaults to0rev.
Line
Line(points, [radius], cap?=, headCap?, tailCap?, headTilt?, tailTilt?) -> shape
Returns a line Polygon.
Size and shape:
-
points(Array): An array of points that form the line. Each point will be connected to the next point in the array. For example,[@(0, 0), @(100, 0)]is a simple two-point line. -
radius(Number): The half-width of the line. If it is a single number (for example,5), the line will have a constant radius. If it is an array of two numbers (for example,[5, 10]), the line's radius will be tapered from the first number to the second number. If there are more than two numbers provided, only the first and last number will be used.
Tilt:
You can tilt the ends of the line.
This is useful if you are laying out a track of multiple lines and want them connect when they go around corners.
For example, going around a right-angled corner, you may tilt the end of the first line by 0.25rev
while the start of the next line you may tilt -0.25rev. This way they will tesselate and not leave a gap.
You can also use this to stylize your games, for example make a parallelogram rather than just a simple line.
headTilt(Number): Tilts the start of the line. A value of0revmeans it will be perpindicular to the line, whereas0.125revwould tilt it by 1/8th of a turn. Defaults to0rev.tailTilt(Number): Tilts the end of the line. Same asheadTiltbut for the end of the line. Defaults to0rev.
Style:
headCap(Boolean): Whether to round the first point in the line. Defaults tofalse.tailCap(Boolean): Whether to round the last point in the line. Defaults tofalse.cap(Boolean): Convenience parameter to set bothheadCapandtailCapat the same time. Defaults tofalse.
Performance note:
This function does some computation to make sure the Line is ready for use.
For example, it removes duplicate and colinear points, calculates all line normals, and calculates the bounding box surrounding the line.
If you are going to need a Line with the same parameters multiple times,
is best to store your Line somewhere and reuse it to reduce unnecessary computation.
Polygon
Polygon(points, border?=) -> shape
Returns a polygon shape.
-
points(Array): An array of points that form the perimeter of the polygon. Each point will be connected to the next point in the array, and then the last point will be connected back onto the first point. -
border(Number): The width of the rounded border surrounding the polygon. Defaults to0.
Performance note:
This function does some computation to make sure the Polygon is ready for use.
For example, it removes duplicate and colinear points,
calculates whether the polygon has clockwise or counter-clockwise winding,
and also calculates the convex decomposition of the polygon.
If you are going to need a Polygon with the same parameters multiple times,
is best to store your Polygon somewhere and reuse it to reduce unnecessary computation.
Rectangle
Rectangle(pos?=, angle?, width?, height?, border?) -> shape
Returns a rectangle Polygon.
-
pos(Vector): Offsets the position of this rectangle by the given vector. Defaults to@(0, 0). -
angle(Number): Rotates the rectangle by the given angle. For example,0.25revwould rotate the rectangle by a quarter turn. Defaults to0rev. -
width(Number): The width of the rectangle. -
height(Number): The height of the rectangle. -
border(Number): The width of the rounded border surrounding the rectangle. Defaults to0.
Rhombus
Rhombus(pos?=, angle?, width, height, border?) -> shape
Returns a rhombus Polygon. A rhombus is like a square squashed from one corner to the opposite corner. Like a diamond or a kite. A rhombus can be used for tiles in a 2D isometric game.
-
pos(Vector): Offsets the position of this rhombus by the given vector. Defaults to@(0, 0). -
angle(Number): Rotates the rhombus by the given angle. For example,0.25revwould rotate the rhombus by a quarter turn. Defaults to0rev. -
width(Number): The width of the rhombus. -
height(Number): The height of the rhombus. -
border(Number): The width of the rounded border surrounding the rhombus. Defaults to0.
Sector
Sector(arc, [radius], pos?=, angle?) -> shape
Returns a sector Polygon. A sector is a slice of a circle. Like a slice of pizza.
-
arc(Number): The angular width of the sector. For example,0.125revwould make 1/8th of a slice of pizza. -
angle(Number): The angle offset of the sector. For example-0.25revwould rotate the sector one quarter turn to the left. Use this to control where the arc starts. Defaults to-0.5 * arcwhich centers the arc across 0 degrees. -
radius(Number): The length from the origin of the sector to the edge. -
pos(Vector): The position offset of the sector. Defaults to@(0, 0).