Difference between revisions of "love.graphics.setColor"

m (Added HSL color link to the See Also section)
(Added table support synopsis+example)
Line 12: Line 12:
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.setColor( rgba )
 +
</source>
 +
=== Arguments ===
 +
{{param|table|rgba|A numerical indexed table with the red, green, blue and alpha values as [[number]]s.}}
 +
=== Returns ===
 +
Nothing.
 +
=== Notes ===
 +
Added in version 0.7.0.
 
== Examples ==
 
== Examples ==
=== Set draw a red circle and a blue one ===
+
=== Draw a red, blue and green circle ===
 
<source lang="lua">
 
<source lang="lua">
 
love.graphics.setColor(255, 0, 0)
 
love.graphics.setColor(255, 0, 0)
 
love.graphics.circle(50, 50, 20, 20)
 
love.graphics.circle(50, 50, 20, 20)
 +
 
love.graphics.setColor(0, 0, 255)
 
love.graphics.setColor(0, 0, 255)
 
love.graphics.circle(50, 100, 20, 20)
 
love.graphics.circle(50, 100, 20, 20)
 +
 +
myColor = {0, 255, 0, 255}
 +
love.graphics.setColor(myColor)
 +
love.graphics.circle(50, 150, 20, 20)
 
</source>
 
</source>
 
=== Display a Venn diagram ===
 
=== Display a Venn diagram ===

Revision as of 19:40, 1 February 2011

Sets the color used for drawing.

Function

Synopsis

love.graphics.setColor( red, green, blue, alpha )

Arguments

number red
The amount of red.
number green
The amount of green.
number blue
The amount of blue.
number alpha (255)
The amount of alpha. The alpha value will be applied to all subsequent draw operations, even the drawing of an image.

Returns

Nothing.

Synopsis

love.graphics.setColor( rgba )

Arguments

table rgba
A numerical indexed table with the red, green, blue and alpha values as numbers.

Returns

Nothing.

Notes

Added in version 0.7.0.

Examples

Draw a red, blue and green circle

love.graphics.setColor(255, 0, 0)
love.graphics.circle(50, 50, 20, 20)

love.graphics.setColor(0, 0, 255)
love.graphics.circle(50, 100, 20, 20)

myColor = {0, 255, 0, 255}
love.graphics.setColor(myColor)
love.graphics.circle(50, 150, 20, 20)

Display a Venn diagram

function love.load()
	baseX = 300
	baseY = 400
	radius = 100
	offsetY = radius*.5*math.sqrt(3)
	love.graphics.setBackgroundColor(255,255,255)
end

function love.draw()
	love.graphics.setColor(255, 0, 0, 100)
	love.graphics.circle('fill', baseX, baseY, radius, 50)
	love.graphics.setColor(0, 255, 0, 100)
	love.graphics.circle('fill', baseX + radius / 2, baseY - offsetY, radius, 50)
	love.graphics.setColor(0, 0, 255, 100)
	love.graphics.circle('fill', baseX + radius, baseY, radius, 50)
end

See Also


Other Languages