Difference between revisions of "love.graphics.arc"

m
(Drawing a rounded borders rectangle)
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
{{newin|[[0.8.0]]|080|type=function}}
 
{{newin|[[0.8.0]]|080|type=function}}
Draws an arc.
+
Draws a filled or unfilled arc at position <code>(x, y)</code>. The arc is drawn from <code>angle1</code> to <code>angle2</code> in [https://en.wikipedia.org/wiki/Radian radians]. The <code>segments</code> parameter determines how many segments are used to draw the arc. The more segments, the smoother the edge.
  
 
== Function ==
 
== Function ==
 +
Draws an arc using the "pie" [[ArcType]].
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
love.graphics.arc( mode, x, y, radius, angle1, angle2, segments )
+
love.graphics.arc( drawmode, x, y, radius, angle1, angle2, segments )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|DrawMode|mode|How to draw the arc.}}
+
{{param|DrawMode|drawmode|How to draw the arc.}}
 
{{param|number|x|The position of the center along x-axis.}}
 
{{param|number|x|The position of the center along x-axis.}}
 
{{param|number|y|The position of the center along y-axis.}}
 
{{param|number|y|The position of the center along y-axis.}}
Line 17: Line 18:
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
 +
 +
== Function ==
 +
{{newin|[[0.10.1]]|101|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.arc( drawmode, arctype, x, y, radius, angle1, angle2, segments )
 +
</source>
 +
=== Arguments ===
 +
{{param|DrawMode|drawmode|How to draw the arc.}}
 +
{{param|ArcType|arctype|The type of arc to draw.}}
 +
{{param|number|x|The position of the center along x-axis.}}
 +
{{param|number|y|The position of the center along y-axis.}}
 +
{{param|number|radius|Radius of the arc.}}
 +
{{param|number|angle1|The angle at which the arc begins.}}
 +
{{param|number|angle2|The angle at which the arc terminates.}}
 +
{{param|number|segments (10)|The number of segments used for drawing the arc.}}
 +
=== Returns ===
 +
Nothing.
 +
 
== Examples ==
 
== Examples ==
 
=== Drawing half a circle ===
 
=== Drawing half a circle ===
Line 28: Line 49:
 
pacwidth = math.pi / 6 -- size of his mouth
 
pacwidth = math.pi / 6 -- size of his mouth
 
function love.draw( )
 
function love.draw( )
   love.graphics.setColor( 255, 255, 0 ) -- pacman needs to be yellow
+
   love.graphics.setColor( 1, 1, 0 ) -- pacman needs to be yellow
 
   love.graphics.arc( "fill", 400, 300, 100, pacwidth, (math.pi * 2) - pacwidth )
 
   love.graphics.arc( "fill", 400, 300, 100, pacwidth, (math.pi * 2) - pacwidth )
 
end
 
end
 
</source>
 
</source>
 +
 +
=== Drawing a rounded sides rectangle ===
 +
<source lang="lua">
 +
quartcircle = math.pi / 2 -- Define 1/4 angle constant
 +
function love.draw( )
 +
  love.graphics.setColor( .7, .7, 1 ) -- Blueish color
 +
  love.graphics.line( 200, 100, 600, 100 )
 +
  love.graphics.line( 200, 300, 600, 300 )
 +
  -- Angles are clockwise, as y value grows when going down
 +
  love.graphics.arc( "line", "open", 200, 200, 100, quartcircle, math.pi+quartcircle )
 +
  love.graphics.arc( "line", "open", 600, 200, 100, -quartcircle, quartcircle)
 +
end
 +
</source>
 +
 +
== Notes ==
 +
The arc is drawn counter clockwise if the starting angle is numerically bigger than the final angle. The arc is drawn clockwise if the final angle is numerically bigger than the starting angle.
 
== See Also ==
 
== See Also ==
 
* [[parent::love.graphics]]
 
* [[parent::love.graphics]]
 
[[Category:Functions]]
 
[[Category:Functions]]
[[Sub-Category:Drawing| ]]
+
[[Sub-Category::Drawing| ]]
 
{{#set:Description=Draws an arc.}}
 
{{#set:Description=Draws an arc.}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.graphics.arc}}
 
{{i18n|love.graphics.arc}}

Latest revision as of 21:07, 26 March 2022

Available since LÖVE 0.8.0
This function is not supported in earlier versions.

Draws a filled or unfilled arc at position (x, y). The arc is drawn from angle1 to angle2 in radians. The segments parameter determines how many segments are used to draw the arc. The more segments, the smoother the edge.

Function

Draws an arc using the "pie" ArcType.

Synopsis

love.graphics.arc( drawmode, x, y, radius, angle1, angle2, segments )

Arguments

DrawMode drawmode
How to draw the arc.
number x
The position of the center along x-axis.
number y
The position of the center along y-axis.
number radius
Radius of the arc.
number angle1
The angle at which the arc begins.
number angle2
The angle at which the arc terminates.
number segments (10)
The number of segments used for drawing the arc.

Returns

Nothing.


Function

Available since LÖVE 0.10.1
This variant is not supported in earlier versions.

Synopsis

love.graphics.arc( drawmode, arctype, x, y, radius, angle1, angle2, segments )

Arguments

DrawMode drawmode
How to draw the arc.
ArcType arctype
The type of arc to draw.
number x
The position of the center along x-axis.
number y
The position of the center along y-axis.
number radius
Radius of the arc.
number angle1
The angle at which the arc begins.
number angle2
The angle at which the arc terminates.
number segments (10)
The number of segments used for drawing the arc.

Returns

Nothing.

Examples

Drawing half a circle

function love.draw( )
  love.graphics.arc( "fill", 400, 300, 100, 0, math.pi )
end

Drawing Pacman

pacwidth = math.pi / 6 -- size of his mouth
function love.draw( )
  love.graphics.setColor( 1, 1, 0 ) -- pacman needs to be yellow
  love.graphics.arc( "fill", 400, 300, 100, pacwidth, (math.pi * 2) - pacwidth )
end

Drawing a rounded sides rectangle

quartcircle = math.pi / 2 -- Define 1/4 angle constant
function love.draw( )
  love.graphics.setColor( .7, .7, 1 ) -- Blueish color
  love.graphics.line( 200, 100, 600, 100 )
  love.graphics.line( 200, 300, 600, 300 )
  -- Angles are clockwise, as y value grows when going down 
  love.graphics.arc( "line", "open", 200, 200, 100, quartcircle, math.pi+quartcircle )
  love.graphics.arc( "line", "open", 600, 200, 100, -quartcircle, quartcircle)
end

Notes

The arc is drawn counter clockwise if the starting angle is numerically bigger than the final angle. The arc is drawn clockwise if the final angle is numerically bigger than the starting angle.

See Also


Other Languages