Guest User

Untitled

a guest
Nov 3rd, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. love.graphics.print_hex = function(str, ax, ay, ...)
  2. local pat = "(.-)#(%x%x%x%x%x%x)"
  3. local s, e, cap, col = str:find(pat, 1)
  4. local last = 1
  5. local _,_,_,a = love.graphics.getColor()
  6. local font = love.graphics.getFont()
  7.  
  8. while s do
  9. if cap == "" and col then
  10. love.graphics.setColor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), a)
  11. end
  12.  
  13. if s ~= 1 or cap ~= "" then
  14. local w = font:getWidth(cap)
  15. love.graphics.print(cap, ax, ay, ...)
  16. ax = ax + w
  17. love.graphics.setColor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), a)
  18. end
  19. last = e + 1
  20. s, e, cap, col = str:find(pat, last)
  21. end
  22.  
  23. if last <= #str then
  24. cap = str:sub(last)
  25. local w = font:getWidth(cap)
  26. love.graphics.print(cap, ax, ay, ...)
  27. end
  28. end
  29.  
  30. function love.load()
  31. f = love.graphics.newFont()
  32. love.graphics.setFont(f)
  33. love.graphics.setColor(255, 0, 0, 255)
  34. end
  35.  
  36. function love.draw()
  37. love.graphics.print_hex("Hel#00ff00l#00ffffo Wo#aabbccrld", 20, 20)
  38. end
Advertisement
Add Comment
Please, Sign In to add comment