Advertisement
Patosho

RGB Clock

Jan 27th, 2015
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. function convert(v,min1,max1,min2,max2)
  2.     return math.floor((((v - min1) * (max2 - min2)) / (max1 - min1)) + min2)
  3. end
  4.  
  5. function eventLoop()
  6.     local t = os.date():sub(12,19)
  7.    
  8.     local h = t:sub(1,2)
  9.     local m = t:sub(4,5)
  10.     local s = t:sub(7,8)
  11.    
  12.     local r = string.format("%X", convert(h, 0, 23, 0, 255))
  13.     local g = string.format("%X", convert(m, 0, 59, 0, 255))
  14.     local b = string.format("%X", convert(s, 0, 59, 0, 255))
  15.    
  16.     local color = string.format("%02X%02X%02X", tonumber(r,16), tonumber(g,16), tonumber(b,16))
  17.    
  18.     local text1 = "<p align='center'><font size='36'>"..t.."</font></p>"
  19.     local text2 = "<p align='center'><font size='24'>"..color.."</font></p>"
  20.    
  21.     ui.addTextArea(0, text1, nil, 20, 40, 200, 60, tonumber(color, 16), nil, 1, true)
  22.     ui.addTextArea(1, text2, nil, 20, 120, 200, 36, tonumber(color, 16), nil, 1, true)
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement