Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- love.graphics.print_hex = function(str, ax, ay, ...)
- local pat = "(.-)#(%x%x%x%x%x%x)"
- local s, e, cap, col = str:find(pat, 1)
- local last = 1
- local _,_,_,a = love.graphics.getColor()
- local font = love.graphics.getFont()
- while s do
- if cap == "" and col then
- love.graphics.setColor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), a)
- end
- if s ~= 1 or cap ~= "" then
- local w = font:getWidth(cap)
- love.graphics.print(cap, ax, ay, ...)
- ax = ax + w
- love.graphics.setColor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), a)
- end
- last = e + 1
- s, e, cap, col = str:find(pat, last)
- end
- if last <= #str then
- cap = str:sub(last)
- local w = font:getWidth(cap)
- love.graphics.print(cap, ax, ay, ...)
- end
- end
- function love.load()
- f = love.graphics.newFont()
- love.graphics.setFont(f)
- love.graphics.setColor(255, 0, 0, 255)
- end
- function love.draw()
- love.graphics.print_hex("Hel#00ff00l#00ffffo Wo#aabbccrld", 20, 20)
- end
Advertisement
Add Comment
Please, Sign In to add comment