Difference between revisions of "love.graphics.setColor"

m (Display a Venn diagram)
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
Sets the color used for drawing.
 
Sets the color used for drawing.
 +
 +
In versions prior to [[11.0]], color component values were within the range of 0 to 255 instead of 0 to 1.
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 9: Line 11:
 
{{param|number|green|The amount of green.}}
 
{{param|number|green|The amount of green.}}
 
{{param|number|blue|The amount of blue.}}
 
{{param|number|blue|The amount of blue.}}
{{param|number|alpha (255)|The amount of alpha.  The alpha value will be applied to all subsequent draw operations, even the drawing of an image.}}
+
{{param|number|alpha (1)|The amount of alpha.  The alpha value will be applied to all subsequent draw operations, even the drawing of an image.}}
 +
=== Returns ===
 +
Nothing.
 +
 
 +
== Function ==
 +
{{newin|[[0.7.0]]|070|type=variant}}
 +
=== 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. The alpha is optional and defaults to 1 if it is left out.}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 
== 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(1, 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, 1)
 
love.graphics.circle(50, 100, 20, 20)
 
love.graphics.circle(50, 100, 20, 20)
 +
 +
myColor = {0, 1, 0, 1}
 +
love.graphics.setColor(myColor)
 +
love.graphics.circle(50, 150, 20, 20)
 
</source>
 
</source>
 
=== Display a Venn diagram ===
 
=== Display a Venn diagram ===
Line 27: Line 45:
 
radius = 100
 
radius = 100
 
offsetY = radius*.5*math.sqrt(3)
 
offsetY = radius*.5*math.sqrt(3)
love.graphics.setBackgroundColor(255,255,255)
+
love.graphics.setBackgroundColor(1, 1, 1)
 
end
 
end
  
 
function love.draw()
 
function love.draw()
love.graphics.setColor(255, 0, 0, 100)
+
love.graphics.setColor(1, 0, 0, 100)
 
love.graphics.circle('fill', baseX, baseY, radius, 50)
 
love.graphics.circle('fill', baseX, baseY, radius, 50)
love.graphics.setColor(0, 255, 0, 100)
+
love.graphics.setColor(0, 1, 0, 100)
 
love.graphics.circle('fill', baseX + radius / 2, baseY - offsetY, radius, 50)
 
love.graphics.circle('fill', baseX + radius / 2, baseY - offsetY, radius, 50)
love.graphics.setColor(0, 0, 255, 100)
+
love.graphics.setColor(0, 0, 1, 100)
 
love.graphics.circle('fill', baseX + radius, baseY, radius, 50)
 
love.graphics.circle('fill', baseX + radius, baseY, radius, 50)
 
end
 
end
 
</source>
 
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::love.graphics]]
 
* [[parent::love.graphics]]
 +
* [[HSL color]] (an alternate color space, based on human perception)
 
[[Category:Functions]]
 
[[Category:Functions]]
 
{{#set:Description=Sets the color used for drawing.}}
 
{{#set:Description=Sets the color used for drawing.}}
 +
{{#set:Since=000}}
 +
{{#set:Sub-Category=State}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.graphics.setColor}}
 
{{i18n|love.graphics.setColor}}

Revision as of 04:58, 1 July 2019

Sets the color used for drawing.

In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 1.

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 (1)
The amount of alpha. The alpha value will be applied to all subsequent draw operations, even the drawing of an image.

Returns

Nothing.

Function

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

Synopsis

love.graphics.setColor( rgba )

Arguments

table rgba
A numerical indexed table with the red, green, blue and alpha values as numbers. The alpha is optional and defaults to 1 if it is left out.

Returns

Nothing.

Examples

Draw a red, blue and green circle

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

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

myColor = {0, 1, 0, 1}
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(1, 1, 1)
end

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

See Also


Other Languages