Skip to content

Commit bc53c82

Browse files
gaelysamparamat
authored andcommittedJun 22, 2017
Add minetest.rgba function that returns ColorString from RGBA or RGB values
1 parent 1425c6d commit bc53c82

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
 

‎builtin/common/misc_helpers.lua

+6
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ function core.explode_scrollbar_event(evt)
511511
return retval
512512
end
513513

514+
--------------------------------------------------------------------------------
515+
function core.rgba(r, g, b, a)
516+
return a and string.format("#%02X%02X%02X%02X", r, g, b, a) or
517+
string.format("#%02X%02X%02X", r, g, b)
518+
end
519+
514520
--------------------------------------------------------------------------------
515521
function core.pos_to_string(pos, decimal_places)
516522
local x = pos.x

‎doc/client_lua_api.md

+4
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,10 @@ Call these functions only at load time!
794794
* See documentation on `minetest.compress()` for supported compression methods.
795795
* currently supported.
796796
* `...` indicates method-specific arguments. Currently, no methods use this.
797+
* `minetest.rgba(red, green, blue[, alpha])`: returns a string
798+
* Each argument is a 8 Bit unsigned integer
799+
* Returns the ColorString from rgb or rgba values
800+
* Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"`
797801
* `minetest.encode_base64(string)`: returns string encoded in base64
798802
* Encodes a string in base64.
799803
* `minetest.decode_base64(string)`: returns string

‎doc/lua_api.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ Example (colored grass block):
580580
description = "Dirt with Grass",
581581
-- Regular tiles, as usual
582582
-- The dirt tile disables palette coloring
583-
tiles = {{name = "default_grass.png"},
583+
tiles = {{name = "default_grass.png"},
584584
{name = "default_dirt.png", color = "white"}},
585585
-- Overlay tiles: define them in the same style
586586
-- The top and bottom tile does not have overlay
@@ -2958,6 +2958,10 @@ These functions return the leftover itemstack.
29582958
* See documentation on `minetest.compress()` for supported compression methods.
29592959
* currently supported.
29602960
* `...` indicates method-specific arguments. Currently, no methods use this.
2961+
* `minetest.rgba(red, green, blue[, alpha])`: returns a string
2962+
* Each argument is a 8 Bit unsigned integer
2963+
* Returns the ColorString from rgb or rgba values
2964+
* Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"`
29612965
* `minetest.encode_base64(string)`: returns string encoded in base64
29622966
* Encodes a string in base64.
29632967
* `minetest.decode_base64(string)`: returns string

0 commit comments

Comments
 (0)
Please sign in to comment.