You are not logged in.

#1 2011-10-25 16:15:07

Ped
Member
From: Bellville South Africa
Registered: 2011-02-18
Posts: 78

Conky Clock

I present to you, dum dum daaa... My personal flavor of the lua-conky-clock!

tYXpidA

Requirements:
packer -S conky-lua
DejaVu Sans

TAR.GS file download

Uncompress this in your ~/ (home) folder and do the "conky -c .conkyrc"
and... tada! There you have it! a clock with a dark transparent background and lit markings. (It's what I've always wanted from Conky! [WARNING: the file is named .conkyrc, do not go and replace your .conkyrc by mistake, that is, if you have some kind of personal attachment to it.]

This is a modification of the Air Clock by Alison Pitt (2009). I just want to say: thank you so much Alison, may you be able to create lots of other crazy inventions.

To be honest, resizing it is a bit impossible because of my modifications. You can edit the Lua file anyway you like though, or just enjoy the splendor of what it is.

Conky:

lua_load ~/.scripts/clock.lua
lua_draw_hook_pre draw_clock

background yes
use_xft yes
xftfont monospace:size=9
xftalpha 1
update_interval 1.0
total_run_times 0
own_window yes
own_window_transparent yes
own_window_type desktop
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 410 410
maximum_width 410
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
default_color white
default_shade_color 000000
default_outline_color d9d7d6
alignment tr
gap_x 12
gap_y 12
no_buffers yes
uppercase no
cpu_avg_samples 2
override_utf8_locale no
color1 cyan
color2 gray
##############################################
#  Output
##############################################
TEXT

Lua:

--[[
Air Clock by Alison Pitt (2009)-- Slightly modified by Ped Moses (2011)

This clock is designed to look like KDE 4.3's "Air" clock, but from inside Conky.

You can adjust the clock's radius and placement, as well as the size and offset of the drop shadow. You can also choose whether to display the seconds hand. This clock updates every time Conky does, so if you want to show seconds, it is recommended that you set update_interval to no more than 0.5s. If you turn off seconds, you can set the update_interval to as long as 30s.  The settings are in the "Settings" section, starting at Line 21.

Call this script in Conky using the following before TEXT (assuming you save this script to ~/.scripts/clock.lua):
    lua_load ~/.scripts/clock.lua
    lua_draw_hook_pre draw_clock
]]

require 'cairo'
function conky_draw_clock()
    if conky_window==nil then return end
    local w=conky_window.width
    local h=conky_window.height
    local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
    cr=cairo_create(cs)
            
    -- Settings
    
        -- What radius should the clock face (not including border) be, in pixels?
        
        local clock_r=118
    
        -- x and y coordinates, relative to the top left corner of Conky, in pixels
        
        local xc=w/2
        local yc=h/2
    
        -- Extent of the shadow, in pixels
        
        shadow_width=5
        
        -- x and y offsets of the drop shadow, relative to the centre of the clock face, in pixels. Can be positive (downward) or negative (upward)
        
        shadow_xoffset=0
        shadow_yoffset=5
        
        -- Do you want to show the second hand? Use this if you use a Conky update_interval > 1s. Can be true or false.
        
        show_seconds=false
    
    -- Grab time
    
    local hours=os.date("%I")
    local mins=os.date("%M")
    local secs=os.date("%S")
    
    secs_arc=(2*math.pi/60)*secs
    mins_arc=(2*math.pi/60)*mins
    hours_arc=(2*math.pi/12)*hours+mins_arc/12
    
    -- Drop shadow
    
    local ds_pat=cairo_pattern_create_radial(xc+shadow_xoffset,yc+shadow_yoffset,clock_r*1.25,xc+shadow_xoffset,yc+shadow_yoffset,clock_r*1.25+shadow_width)
    cairo_pattern_add_color_stop_rgba(ds_pat,0,0,0,0,0.5)
    cairo_pattern_add_color_stop_rgba(ds_pat,1,0,0,0,0)
    
    cairo_move_to(cr,0,0)
    cairo_line_to(cr,w,0)
    cairo_line_to(cr,w,h)
    cairo_line_to(cr,0,h)
    cairo_new_sub_path(cr)
    cairo_arc(cr,xc,yc,clock_r*1.25,0,2*math.pi)
    cairo_set_source(cr,ds_pat)
    cairo_set_fill_rule(cr,CAIRO_FILL_RULE_EVEN_ODD)
    cairo_fill(cr)
    
    -- Glassy border
    
    cairo_arc(cr,xc,yc,clock_r*1.1,0,2*math.pi)
    cairo_set_source_rgba(cr,0.5,0.5,0.5,0)
    cairo_set_line_width(cr,0)
    cairo_stroke(cr)
    
    local border_pat=cairo_pattern_create_linear(xc,yc-clock_r*1.25,xc,yc+clock_r*1.25)
    
    cairo_pattern_add_color_stop_rgba(border_pat,0,0,0,0,0.2)
    cairo_pattern_add_color_stop_rgba(border_pat,0.3,0,0,0,0.35)
    cairo_pattern_add_color_stop_rgba(border_pat,0.5,0,0,0,0.35)
    cairo_pattern_add_color_stop_rgba(border_pat,0.7,0,0,0,0.35)
    cairo_pattern_add_color_stop_rgba(border_pat,1,0,0,0,0.2)
    cairo_set_source(cr,border_pat)
    cairo_arc(cr,xc,yc,clock_r*1.125,0,2*math.pi)
    cairo_close_path(cr)
    cairo_set_line_width(cr,clock_r*0.25)
    cairo_stroke(cr)
    
    -- Set clock face
    
    cairo_arc(cr,xc,yc,clock_r,0,2*math.pi)
    cairo_close_path(cr)
    
    local face_pat=cairo_pattern_create_radial(xc,yc-clock_r*0.75,0,xc,yc,clock_r)
    
    cairo_pattern_add_color_stop_rgba(face_pat,0,0.3,0.3,0.3,0.4)
    cairo_pattern_add_color_stop_rgba(face_pat,0.5,0.3,0.3,0.3,0.4)
    cairo_pattern_add_color_stop_rgba(face_pat,1,0,0,0,0.4)
    cairo_set_source(cr,face_pat)
    cairo_fill_preserve(cr)
    cairo_set_source_rgba(cr,0,0,0,0.7)
    cairo_set_line_width(cr, 1)
    cairo_stroke (cr)
    
    -- Draw hour hand
    
    xh=xc+0.46*clock_r*math.sin(hours_arc)
    yh=yc-0.46*clock_r*math.cos(hours_arc)
    cairo_move_to(cr,xc,yc)
    cairo_line_to(cr,xh,yh)
    
    cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
    cairo_set_line_width(cr,4)
    cairo_set_source_rgba(cr,1,1,1,1)
    cairo_stroke(cr)
    
    -- Draw minute hand
    
    xm=xc+0.74*clock_r*math.sin(mins_arc)
    ym=yc-0.74*clock_r*math.cos(mins_arc)
    cairo_move_to(cr,xc,yc)
    cairo_line_to(cr,xm,ym)
    
    cairo_set_line_width(cr,3)
    cairo_stroke(cr)
    
    -- Draw seconds hand
    
    if show_seconds then
        xs=xc+0.9*clock_r*math.sin(secs_arc)
        ys=yc-0.9*clock_r*math.cos(secs_arc)
        cairo_move_to(cr,xc,yc)
        cairo_line_to(cr,xs,ys)
    
        cairo_set_line_width(cr,1)
        cairo_stroke(cr)
    end

cairo_select_font_face (cr, "DejaVu Sans", CAIRO_FONT_SLANT_NORMAL,
                               CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 36.0);

cairo_move_to (cr, 186.0, 131.0);
cairo_show_text (cr, "12");

cairo_move_to (cr, 199.0, 316.0);
cairo_show_text (cr, "6");

cairo_move_to (cr, 102.0, 226.0);
cairo_show_text (cr, "9");

cairo_move_to (cr, 295.0, 223.5);
cairo_show_text (cr, "3");

cairo_move_to (cr, 246.0, 146.0);
cairo_show_text (cr, "1");

cairo_move_to (cr, 279.0, 176.0);
cairo_show_text (cr, "2");

cairo_move_to (cr, 154.0, 306.0);
cairo_show_text (cr, "7");

cairo_move_to (cr, 119.0, 272.0);
cairo_show_text (cr, "8");

cairo_move_to (cr, 246.0, 304.0);
cairo_show_text (cr, "4");

cairo_move_to (cr, 279.0, 271.0);
cairo_show_text (cr, "5");

cairo_move_to (cr, 104.0, 183.0);
cairo_show_text (cr, "10");

cairo_move_to (cr, 137.0, 146.0);
cairo_show_text (cr, "11");


end

[Edit]

Hi people! I'm motivating you
To Present your own clocks over here or just to provide a few links to your favarout clocks.

Secondly: The Lua file is not dependent to the name of the conkyrc file. you can call it whatever you want and use conky to start it up. To those uninformed: you can have 2 conkys at startup, no problem except that conky doesnt truly use real transparency. That means you cant have the two of them on top of each other.

Finaly, some more cool pics of my flavor!
tYjFrdwtYjFregtYjFsZAtYjFsZgtYjFsZwtYjFsaQ


Now everybody knows what I did at four. lol

Last edited by Ped (2011-10-30 09:27:59)


P E Destrian of life
"Life's challenges are not supposed to paralyze you, they're supposed to help you discover who you are." -Bernice Johnson Reagon

Offline

#2 2011-10-26 03:50:19

pablokal
Administrator
From: Nijmegen, Holland
Registered: 2010-10-12
Posts: 3,634
Website

Re: Conky Clock

Thanks for sharing this neat clock.


Getting your questions answered here at ArchBang Forums
Please! Always give hardware info, if there is a chance that 's relevant: #lspci -vnn
On Arch(bang) and Openbox: http://stillstup.blogspot.com/

Offline

Board footer

Powered by FluxBB