Skip to content

Commit

Permalink
Add minetest.rgba function that returns ColorString from RGBA or RGB …
Browse files Browse the repository at this point in the history
…values
  • Loading branch information
gaelysam authored and paramat committed Jun 22, 2017
1 parent 1425c6d commit bc53c82
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions builtin/common/misc_helpers.lua
Expand Up @@ -511,6 +511,12 @@ function core.explode_scrollbar_event(evt)
return retval
end

--------------------------------------------------------------------------------
function core.rgba(r, g, b, a)
return a and string.format("#%02X%02X%02X%02X", r, g, b, a) or
string.format("#%02X%02X%02X", r, g, b)
end

--------------------------------------------------------------------------------
function core.pos_to_string(pos, decimal_places)
local x = pos.x
Expand Down
4 changes: 4 additions & 0 deletions doc/client_lua_api.md
Expand Up @@ -794,6 +794,10 @@ Call these functions only at load time!
* See documentation on `minetest.compress()` for supported compression methods.
* currently supported.
* `...` indicates method-specific arguments. Currently, no methods use this.
* `minetest.rgba(red, green, blue[, alpha])`: returns a string
* Each argument is a 8 Bit unsigned integer
* Returns the ColorString from rgb or rgba values
* Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"`
* `minetest.encode_base64(string)`: returns string encoded in base64
* Encodes a string in base64.
* `minetest.decode_base64(string)`: returns string
Expand Down
6 changes: 5 additions & 1 deletion doc/lua_api.txt
Expand Up @@ -580,7 +580,7 @@ Example (colored grass block):
description = "Dirt with Grass",
-- Regular tiles, as usual
-- The dirt tile disables palette coloring
tiles = {{name = "default_grass.png"},
tiles = {{name = "default_grass.png"},
{name = "default_dirt.png", color = "white"}},
-- Overlay tiles: define them in the same style
-- The top and bottom tile does not have overlay
Expand Down Expand Up @@ -2958,6 +2958,10 @@ These functions return the leftover itemstack.
* See documentation on `minetest.compress()` for supported compression methods.
* currently supported.
* `...` indicates method-specific arguments. Currently, no methods use this.
* `minetest.rgba(red, green, blue[, alpha])`: returns a string
* Each argument is a 8 Bit unsigned integer
* Returns the ColorString from rgb or rgba values
* Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"`
* `minetest.encode_base64(string)`: returns string encoded in base64
* Encodes a string in base64.
* `minetest.decode_base64(string)`: returns string
Expand Down

0 comments on commit bc53c82

Please sign in to comment.