Difference between revisions of "love.graphics.polygon"

m (Testing another format for the image.)
(21 intermediate revisions by 14 users not shown)
Line 1: Line 1:
 +
Draw a polygon.
 +
 +
Following the mode argument, this function can accept multiple numeric arguments or a single table of numeric arguments. In either case the arguments are interpreted as alternating x and y coordinates of the polygon's vertices.
  
Draw a polygon.
+
{{notice|When in '''fill''' mode, the polygon must be [http://en.wikipedia.org/wiki/Convex_polygon convex] and [http://en.wikipedia.org/wiki/Simple_polygon simple] or rendering artifacts may occur. [[love.math.triangulate]] and [[love.math.isConvex]] can be used in [[0.9.0]]+.}}
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 8: Line 11:
 
=== Arguments ===
 
=== Arguments ===
 
{{param|DrawMode|mode|How to draw the polygon.}}
 
{{param|DrawMode|mode|How to draw the polygon.}}
{{param|numbers|...|The vertices of the polygon.}}
+
{{param|number|...|The vertices of the polygon.}}
 +
=== Returns ===
 +
Nothing.
 +
== Function ==
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.polygon( mode, vertices )
 +
</source>
 +
=== Arguments ===
 +
{{param|DrawMode|mode|How to draw the polygon.}}
 +
{{param|table|vertices|The vertices of the polygon as a table.}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
== Examples ==
 +
=== Two ways of drawing the same triangle ===
 +
[[File:Polygon_triangle.png|upright=0.5|thumb|right|top|Triangle drawn using love.graphics.polygon]]
 +
This example shows how to give the coordinates explicitly and how to pass a table argument.
 +
<source lang="lua">
 +
-- giving the coordinates directly
 +
love.graphics.polygon('fill', 100, 100, 200, 100, 150, 200)
 +
 +
-- defining a table with the coordinates
 +
-- this table could be built incrementally too
 +
local vertices = {100, 100, 200, 100, 150, 200}
 +
 +
-- passing the table to the function as a second argument
 +
love.graphics.polygon('fill', vertices)
 +
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::love.graphics]]
 
* [[parent::love.graphics]]
 +
* [[love.math.triangulate]]
 +
* [[love.math.isConvex]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 +
[[Sub-Category::Drawing| ]]
 
{{#set:Description=Draw a polygon.}}
 
{{#set:Description=Draw a polygon.}}
 +
{{#set:Since=040}}
 +
{{#set:PrettySince=0.4.0}}
 +
== Other Languages ==
 +
{{i18n|love.graphics.polygon}}

Revision as of 21:04, 3 November 2016

Draw a polygon.

Following the mode argument, this function can accept multiple numeric arguments or a single table of numeric arguments. In either case the arguments are interpreted as alternating x and y coordinates of the polygon's vertices.

O.png When in fill mode, the polygon must be convex and simple or rendering artifacts may occur. love.math.triangulate and love.math.isConvex can be used in 0.9.0+.  


Function

Synopsis

love.graphics.polygon( mode, ... )

Arguments

DrawMode mode
How to draw the polygon.
number ...
The vertices of the polygon.

Returns

Nothing.

Function

Synopsis

love.graphics.polygon( mode, vertices )

Arguments

DrawMode mode
How to draw the polygon.
table vertices
The vertices of the polygon as a table.

Returns

Nothing.

Examples

Two ways of drawing the same triangle

Triangle drawn using love.graphics.polygon

This example shows how to give the coordinates explicitly and how to pass a table argument.

-- giving the coordinates directly
love.graphics.polygon('fill', 100, 100, 200, 100, 150, 200)

-- defining a table with the coordinates
-- this table could be built incrementally too
local vertices = {100, 100, 200, 100, 150, 200}

-- passing the table to the function as a second argument
love.graphics.polygon('fill', vertices)

See Also



Other Languages