SHARE
TWEET

binClock

a guest Jun 11th, 2014 255 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  local binClock = wibox.widget.base.make_widget()
  2.  binClock.radius = 1.5
  3.  binClock.shift = 1.8
  4.  binClock.farShift = 2
  5.  binClock.border = 1
  6.  binClock.lineWidth = 1
  7.  binClock.colorActive = beautiful.bg_focus
  8.  
  9.  binClock.fit = function(binClock, width, height)
  10.         local size = math.min(width, height)
  11.         return 6 * 2 * binClock.radius + 5 * binClock.shift + 2 * binClock.farShift + 2 * binClock.border + 2 * binClock.border, size
  12.  end
  13.  
  14.  binClock.draw = function(binClock, wibox, cr, width, height)
  15.         local curTime = os.date("*t")
  16.  
  17.         local column = {}
  18.         table.insert(column, string.format("%04d", binClock:dec_bin(string.sub(string.format("%02d", curTime.hour), 1, 1))))
  19.         table.insert(column, string.format("%04d", binClock:dec_bin(string.sub(string.format("%02d", curTime.hour), 2, 2))))
  20.         table.insert(column, string.format("%04d", binClock:dec_bin(string.sub(string.format("%02d", curTime.min), 1, 1))))
  21.         table.insert(column, string.format("%04d", binClock:dec_bin(string.sub(string.format("%02d", curTime.min), 2, 2))))
  22.         table.insert(column, string.format("%04d", binClock:dec_bin(string.sub(string.format("%02d", curTime.sec), 1, 1))))
  23.         table.insert(column, string.format("%04d", binClock:dec_bin(string.sub(string.format("%02d", curTime.sec), 2, 2))))
  24.  
  25.         local bigColumn = 0
  26.         for i = 0, 5 do
  27.                 if math.floor(i / 2) > bigColumn then
  28.                         bigColumn = bigColumn + 1
  29.                 end
  30.                 for j = 0, 3 do
  31.                         if string.sub(column[i + 1], j + 1, j + 1) == "0" then
  32.                                 active = false
  33.                         else
  34.                                 active = true
  35.                         end
  36.                         binClock:draw_point(cr, bigColumn, i, j, active)
  37.                 end
  38.         end
  39.  end
  40.  
  41.  binClock.dec_bin = function(binClock, inNum)
  42.         inNum = tonumber(inNum)
  43.         local base, enum, outNum, rem = 2, "01", "", 0
  44.         while inNum > (base - 1) do
  45.                 inNum, rem = math.floor(inNum / base), math.fmod(inNum, base)
  46.                 outNum = string.sub(enum, rem + 1, rem + 1) .. outNum
  47.         end
  48.         outNum = inNum .. outNum
  49.         return outNum
  50.  end
  51.  
  52.  binClock.draw_point = function(binClock, cr, bigColumn, column, row, active)
  53.         cr:arc(binClock.border + column * (2 * binClock.radius + binClock.shift) + bigColumn * binClock.farShift + binClock.radius,
  54.                  binClock.border + row * (2 * binClock.radius + binClock.shift) + binClock.radius, 2, 0, 2 * math.pi)
  55.         if active then
  56.                 cr:set_source_rgba(0, 0.5, 0, 1)
  57.         else
  58.                 cr:set_source_rgba(0.5, 0.5, 0.5, 1)
  59.         end
  60.         cr:fill()
  61.  end
  62.  
  63.  binClocktimer = timer { timeout = 1 }
  64.  binClocktimer:connect_signal("timeout", function() binClock:emit_signal("widget::updated") end)
  65.  binClocktimer:start()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top