Difference between revisions of "love.graphics.setColor"
m |
m |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | Sets the color used for drawing. | + | Sets the color used for drawing. The color is used for all subsequent draw operations. |
+ | |||
+ | 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 ( | + | {{param|number|alpha (1)|The amount of alpha.}} |
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
Line 20: | Line 22: | ||
</source> | </source> | ||
=== Arguments === | === 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 | + | {{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 the color from r, g, b bytes === | ||
+ | Using [[love.math.colorFromBytes]] we can specify color components in the range 0..255. | ||
+ | <source lang="lua"> | ||
+ | love.graphics.setColor(love.math.colorFromBytes(128, 234, 255)) | ||
+ | </source> | ||
+ | |||
=== Draw a red, blue and green circle === | === Draw a red, blue and green circle === | ||
<source lang="lua"> | <source lang="lua"> | ||
− | love.graphics.setColor( | + | function love.draw() |
− | love.graphics.circle(50, 50 | + | love.graphics.setColor(1, 0, 0) |
+ | love.graphics.circle("fill", 50,50, 20) | ||
− | love.graphics.setColor(0, 0, | + | love.graphics.setColor(0, 0, 1) |
− | love.graphics.circle(50, 100 | + | love.graphics.circle("fill", 50,100, 20) |
− | myColor = {0, | + | local myColor = {0, 1, 0, 1} |
− | love.graphics.setColor(myColor) | + | love.graphics.setColor(myColor) |
− | love.graphics.circle(50, 150 | + | love.graphics.circle("fill", 50,150, 20) |
+ | end | ||
</source> | </source> | ||
+ | |||
=== Display a Venn diagram === | === Display a Venn diagram === | ||
<source lang="lua"> | <source lang="lua"> | ||
function love.load() | function love.load() | ||
− | + | love.graphics.setBackgroundColor(1, 1, 1) | |
− | |||
− | |||
− | |||
− | love.graphics.setBackgroundColor( | ||
end | end | ||
function love.draw() | function love.draw() | ||
− | love.graphics.setColor( | + | local baseX = love.graphics.getWidth()/2 |
− | love.graphics.circle( | + | local baseY = 400 |
− | love.graphics.setColor( | + | local radius = 100 |
− | love.graphics.circle( | + | local offsetY = radius/2 * math.sqrt(3) |
− | love.graphics.setColor( | + | |
− | love.graphics.circle( | + | love.graphics.setBlendMode("multiply", "premultiplied") |
+ | love.graphics.setColor(1, .6, .6) | ||
+ | love.graphics.circle("fill", baseX-radius/2, baseY, radius) | ||
+ | love.graphics.setColor(.6, 1, .6) | ||
+ | love.graphics.circle("fill", baseX, baseY-offsetY, radius) | ||
+ | love.graphics.setColor(.6, .6, 1) | ||
+ | love.graphics.circle("fill", baseX+radius/2, baseY, radius) | ||
end | end | ||
</source> | </source> | ||
+ | |||
== See Also == | == See Also == | ||
* [[parent::love.graphics]] | * [[parent::love.graphics]] | ||
+ | * [[love.math.colorFromBytes]] | ||
* [[HSL color]] (an alternate color space, based on human perception) | * [[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:Since=000}} | ||
+ | {{#set:Sub-Category=State}} | ||
== Other Languages == | == Other Languages == | ||
{{i18n|love.graphics.setColor}} | {{i18n|love.graphics.setColor}} |
Latest revision as of 21:03, 29 April 2024
Sets the color used for drawing. The color is used for all subsequent draw operations.
In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 1.
Contents
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.
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
Set the color from r, g, b bytes
Using love.math.colorFromBytes we can specify color components in the range 0..255.
love.graphics.setColor(love.math.colorFromBytes(128, 234, 255))
Draw a red, blue and green circle
function love.draw()
love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", 50,50, 20)
love.graphics.setColor(0, 0, 1)
love.graphics.circle("fill", 50,100, 20)
local myColor = {0, 1, 0, 1}
love.graphics.setColor(myColor)
love.graphics.circle("fill", 50,150, 20)
end
Display a Venn diagram
function love.load()
love.graphics.setBackgroundColor(1, 1, 1)
end
function love.draw()
local baseX = love.graphics.getWidth()/2
local baseY = 400
local radius = 100
local offsetY = radius/2 * math.sqrt(3)
love.graphics.setBlendMode("multiply", "premultiplied")
love.graphics.setColor(1, .6, .6)
love.graphics.circle("fill", baseX-radius/2, baseY, radius)
love.graphics.setColor(.6, 1, .6)
love.graphics.circle("fill", baseX, baseY-offsetY, radius)
love.graphics.setColor(.6, .6, 1)
love.graphics.circle("fill", baseX+radius/2, baseY, radius)
end
See Also
- love.graphics
- love.math.colorFromBytes
- HSL color (an alternate color space, based on human perception)
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info