require "cairo" -- Plan 9 style analog clock -- Cream face, cyan border, simple black hands local border_width = 8 local border_color = { 0.918, 1.0, 1.0, 1.0 } -- #EAFFFF local face_color = { 1.0, 1.0, 0.918, 1.0 } -- #FFFFEA (Plan 9 cream) local hand_color = { 0.05, 0.05, 0.05, 1.0 } -- near black local tick_color = { 0.3, 0.3, 0.3, 1.0 } -- dark grey local second_color = { 0.83, 0.42, 0.42, 1.0 } -- #D46A6A muted red local center_color = { 0.3, 0.3, 0.3, 1.0 } function conky_draw_clock() if conky_window == nil then return end local cs = cairo_xlib_surface_create( conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height ) local cr = cairo_create(cs) local w = conky_window.width local h = conky_window.height local cx = w / 2 local cy = h / 2 local radius = math.min(w, h) / 2 - border_width - 8 -- Border (4 filled rectangles) local bw = border_width cairo_set_source_rgba(cr, table.unpack(border_color)) cairo_rectangle(cr, 0, 0, w, bw) cairo_rectangle(cr, 0, h - bw, w, bw) cairo_rectangle(cr, 0, 0, bw, h) cairo_rectangle(cr, w - bw, 0, bw, h) cairo_fill(cr) -- Clock face cairo_set_source_rgba(cr, table.unpack(face_color)) cairo_arc(cr, cx, cy, radius, 0, 2 * math.pi) cairo_fill(cr) -- Face outline cairo_set_source_rgba(cr, table.unpack(tick_color)) cairo_set_line_width(cr, 1.5) cairo_arc(cr, cx, cy, radius, 0, 2 * math.pi) cairo_stroke(cr) -- Hour ticks for i = 0, 11 do local angle = (i * 30 - 90) * math.pi / 180 local inner = radius * 0.85 local outer = radius * 0.95 local tick_w = 2.0 if i % 3 == 0 then inner = radius * 0.78 tick_w = 3.0 end cairo_set_line_width(cr, tick_w) cairo_set_source_rgba(cr, table.unpack(tick_color)) cairo_move_to(cr, cx + inner * math.cos(angle), cy + inner * math.sin(angle)) cairo_line_to(cr, cx + outer * math.cos(angle), cy + outer * math.sin(angle)) cairo_stroke(cr) end -- Get time local hours = tonumber(os.date("%I")) local mins = tonumber(os.date("%M")) local secs = tonumber(os.date("%S")) -- Hour hand local hour_angle = ((hours + mins / 60) * 30 - 90) * math.pi / 180 cairo_set_source_rgba(cr, table.unpack(hand_color)) cairo_set_line_width(cr, 4) cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND) cairo_move_to(cr, cx, cy) cairo_line_to(cr, cx + radius * 0.5 * math.cos(hour_angle), cy + radius * 0.5 * math.sin(hour_angle)) cairo_stroke(cr) -- Minute hand local min_angle = ((mins + secs / 60) * 6 - 90) * math.pi / 180 cairo_set_source_rgba(cr, table.unpack(hand_color)) cairo_set_line_width(cr, 2.5) cairo_move_to(cr, cx, cy) cairo_line_to(cr, cx + radius * 0.72 * math.cos(min_angle), cy + radius * 0.72 * math.sin(min_angle)) cairo_stroke(cr) -- Second hand local sec_angle = (secs * 6 - 90) * math.pi / 180 cairo_set_source_rgba(cr, table.unpack(second_color)) cairo_set_line_width(cr, 1.2) cairo_move_to(cr, cx, cy) cairo_line_to(cr, cx + radius * 0.78 * math.cos(sec_angle), cy + radius * 0.78 * math.sin(sec_angle)) cairo_stroke(cr) -- Center dot cairo_set_source_rgba(cr, table.unpack(center_color)) cairo_arc(cr, cx, cy, 4, 0, 2 * math.pi) cairo_fill(cr) cairo_destroy(cr) cairo_surface_destroy(cs) end