SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#76 2013-03-08 11:10:06

dk75
#! Junkie
Registered: 2012-06-14
Posts: 250

Re: HOW TO : using lua scripts in conky

borntwisted wrote:

Thanks for taking the time to explain all this mrpeachy, used lua in conky for quite a while but not fully understood it apart from minor modification to other people's scripts, so really appreciate it being explained smile

There might be a minor typo in the first post, think you meant string1*string2, otherwise it would be a loop?

mrpeachy wrote:

Using Lua scripts in conky

eg

string1=5
string2=9
string3=string1*string3

in this case string3 holds the value 45

Actually it it's completely genuine (apart from "in this case string3 holds the value 45" tongue ).
It will not raise any "loop" event, because every variable manipulation is done on it's copy in memory before assigning results:

string3 = 'copy of string1' * 'copy of string3'

That's why

value = value + 1

works alright too.


Debian Sid (Minted) x86_64/3.12-10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Intel X3100
Lenovo T61, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
Linux user No.: 483055 | Conky Pitstop

Offline

Help fund CrunchBang, donate to the project!

#77 2013-06-30 11:07:57

v4let3
Member
Registered: 2013-06-08
Posts: 23

Re: HOW TO : using lua scripts in conky

Hey dude can u point it out where did u learn all this x)?
Plz i rly like to know more about this.

Offline

#78 2013-07-01 11:34:47

dk75
#! Junkie
Registered: 2012-06-14
Posts: 250

Re: HOW TO : using lua scripts in conky

It's hard for me to point out one place to learn.
Most of my knowledge come with time of using computers and scripting with various languages.

Need to copy variable in order to add it to other and store the result in original one is long time forgotten.

If you want to learn more about LUA then there's tons of LUA tutorials. Including official one where they state that you could make manipulations and storage it on same variable.

If you want to learn how incorporate LUA into Conky then there is "Monster Conky Thread" here, or at Ubuntu forum, there is ConkyPitstop from my sig with a ton of scripts and tutorials.
There is also Cairographics site with LUA Cairo tutorials and manual.


Debian Sid (Minted) x86_64/3.12-10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Intel X3100
Lenovo T61, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
Linux user No.: 483055 | Conky Pitstop

Offline

#79 2013-07-01 12:44:39

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,287
Website

Re: HOW TO : using lua scripts in conky

And you forgot this very thread ... see post #1  big_smile


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#80 2013-07-02 09:21:12

lionhead
#! Junkie
From: Dagobah / Germany
Registered: 2011-01-22
Posts: 456

Re: HOW TO : using lua scripts in conky

i just found this code from mrpeachy:

require 'cairo'

function conky_draw_fig()
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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates>5 then
--##############################################################################
--##############################################################################
--setup bars
ad=15

rootbar=tonumber(conky_parse("${fs_used_perc /}"))
pass={bnum=rootbar,barx=7,bary=316+ad,bhigh=10,blong=194,bout=0};bar(pass)

homebar=tonumber(conky_parse("${fs_used_perc /home}"))
pass={bnum=homebar,barx=7,bary=350+ad,bhigh=10,blong=194,bout=0};bar(pass)

--##############################################################################
--##############################################################################
end-- if updates>5
end-- end main function

function bar(t)
local bnum=t.bnum
if t.bmax==nil then bmax=100 else bmax=t.bmax end
local barx=t.barx+0.5
local bary=t.bary+0.5
local bhigh=t.bhigh
local blong=t.blong
local bout=t.bout
local length=((bnum/bmax)*blong)
cairo_rectangle (cr,barx,bary,length,-bhigh)
cairo_set_source_rgba (cr,0,1,0,1)
cairo_fill (cr)
if bout==1 then
cairo_rectangle (cr,barx,bary,blong,-bhigh)
cairo_set_source_rgba (cr,1,1,1,1)
cairo_set_line_width (cr,1)
cairo_stroke (cr)
end
end

this is a screenshot: http://conky.pitstop.free.fr/wiki/image … achy-1.jpg

it seems that it only works with older versions of conky. if i try this code it only displays 'normal' bars sad

i use conky 1.9.0.2.

Offline

#81 2013-07-02 10:47:00

dk75
#! Junkie
Registered: 2012-06-14
Posts: 250

Re: HOW TO : using lua scripts in conky

Sector11 wrote:

And you forgot this very thread ... see post #1  big_smile

Maybe because I didn't used it as my tutorial...   devil


Debian Sid (Minted) x86_64/3.12-10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Intel X3100
Lenovo T61, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
Linux user No.: 483055 | Conky Pitstop

Offline

#82 2013-12-19 22:01:37

chalkyjoe
New Member
Registered: 2013-12-19
Posts: 1

Re: HOW TO : using lua scripts in conky

Hey Peachy, great tutorials! Although I was wondering, is there any way to use newlines from within the LUA file? I am making a timetable script for my classes, and want it to be vaguely something like:

first class name
first class room
first class time
first class teacher

second class name
second class room
second class time
second class teacher


etc.

But on different days I have different amount of classes, so I can't just put each line in an individual variable and move the ypos down a few pixels.

When I did something like "timetable = "lesson1 \n lesson2"" the \n just appeared as a square character.

Thanks for your time smile

Offline

#83 2014-03-03 10:33:05

tbk515
New Member
From: Pld, BG, EU, EA, SS, MW
Registered: 2014-03-03
Posts: 2

Re: HOW TO : using lua scripts in conky

Hi to all!
How to add more watch hands with Lua? I want 3 more for:
- numeric representation of the day of the week (%u);
- two-digit day of the month (with leading zeros) (%d);
- general example for other functions.
Is it possible?
I want to make chronograph watch. The clock background will be image from Conky, and I need only from watch hands.
Here are my lua file, which is in the process of editing:

--[[
Clock Rings by Linux Mint (2011) reEdited by despot77

This script draws percentage meters as rings, and also draws clock hands if you want! It is fully customisable; all options are described in the script. This script is based off a combination of my clock.lua script and my rings.lua script.

IMPORTANT: if you are using the 'cpu' function, it will cause a segmentation fault if it tries to draw a ring straight away. The if statement on line 145 uses a delay to make sure that this doesn't happen. It calculates the length of the delay by the number of updates since Conky started. Generally, a value of 5s is long enough, so if you update Conky every 1s, use update_num>5 in that if statement (the default). If you only update Conky every 2s, you should change it to update_num>3; conversely if you update Conky every 0.5s, you should use update_num>10. ALSO, if you change your Conky, is it best to use "killall conky; conky" to update it, otherwise the update_num will not be reset and you will get an error.

To call this script in Conky, use the following (assuming that you save this script to ~/scripts/rings.lua):
    lua_load ~/scripts/clock_rings.lua
    lua_draw_hook_pre clock_rings
    
Changelog:
+ v1.0 -- Original release (30.09.2009)
   v1.1p -- Jpope edit londonali1010 (05.10.2009)
*v 2011mint -- reEdit despot77 (18.02.2011)
]]

settings_table = {
    {
        -- Edit this table to customise your rings.
        -- You can create more rings simply by adding more elements to settings_table.
        -- "name" is the type of stat to display; you can choose from 'cpu', 'memperc', 'fs_used_perc', 'battery_used_perc'.
        name='time',
        -- "arg" is the argument to the stat type, e.g. if in Conky you would write ${cpu cpu0}, 'cpu0' would be the argument. If you would not use an argument in the Conky variable, use ''.
        arg='%I.%M',
        -- "max" is the maximum value of the ring. If the Conky variable outputs a percentage, use 100.
        max=12,
        -- "bg_colour" is the colour of the base ring.
        bg_colour=0xffffff,
        -- "bg_alpha" is the alpha value of the base ring.
        bg_alpha=0,
        -- "fg_colour" is the colour of the indicator part of the ring.
        fg_colour=0xFF6600,
        -- "fg_alpha" is the alpha value of the indicator part of the ring.
        fg_alpha=0,
        -- "x" and "y" are the x and y coordinates of the centre of the ring, relative to the top left corner of the Conky window.
        x=100, y=150,
        -- "radius" is the radius of the ring.
        radius=50,
        -- "thickness" is the thickness of the ring, centred around the radius.
        thickness=5,
        -- "start_angle" is the starting angle of the ring, in degrees, clockwise from top. Value can be either positive or negative.
        start_angle=0,
        -- "end_angle" is the ending angle of the ring, in degrees, clockwise from top. Value can be either positive or negative, but must be larger than start_angle.
        end_angle=360
    },
    {
        name='time',
        arg='%S',
        max=60,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0xFF6600,
        fg_alpha=0.6,
        x=100, y=150,
        radius=20,
        thickness=5,
        start_angle=0,
        end_angle=360
    },
    {
        name='time',
        arg='%u',
        max=7,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0xFF6600,
        fg_alpha=0.8,
        x=100, y=250,
        radius=15,
        thickness=50,
        start_angle=0,
        end_angle=360
    },
    {
        name='time',
        arg='%d',
        max=31,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0xFF6600,
        fg_alpha=0.8,
        x=100, y=350,
        radius=25,
        thickness=49,
        start_angle=90,
        end_angle=270
    },
}

-- Use these settings to define the origin and extent of your clock.

clock_r=96

-- "clock_x" and "clock_y" are the coordinates of the centre of the clock, in pixels, from the top left of the Conky window.

clock_x=96
clock_y=96

show_seconds=true

require 'cairo'

function rgb_to_r_g_b(colour,alpha)
    return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end

function draw_ring(cr,t,pt)
    local w,h=conky_window.width,conky_window.height
    
    local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']
    local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']

    local angle_0=sa*(2*math.pi/360)-math.pi/2
    local angle_f=ea*(2*math.pi/360)-math.pi/2
    local t_arc=t*(angle_f-angle_0)

    -- Draw background ring

    cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)
    cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
    cairo_set_line_width(cr,ring_w)
    cairo_stroke(cr)
    
    -- Draw indicator ring

    cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)
    cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
    cairo_stroke(cr)        
end

function draw_clock_hands(cr,xc,yc)
    local secs,mins,hours,secs_arc,mins_arc,hours_arc
    local xh,yh,xm,ym,xs,ys
    
    secs=os.date("%S")    
    mins=os.date("%M")
    hours=os.date("%I")
        
    secs_arc=(2*math.pi/60)*secs
    mins_arc=(2*math.pi/60)*mins+secs_arc/60
    hours_arc=(2*math.pi/12)*hours+mins_arc/12
        
    -- Draw hour hand
    
    xh=xc+0.7*clock_r*math.sin(hours_arc)
    yh=yc-0.7*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,5)
    cairo_set_source_rgba(cr,1.0,1.0,1.0,1.0)
    cairo_stroke(cr)
    
    -- Draw minute hand
    
    xm=xc+clock_r*math.sin(mins_arc)
    ym=yc-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+clock_r*math.sin(secs_arc)
        ys=yc-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
end

function conky_clock_rings()
    local function setup_rings(cr,pt)
        local str=''
        local value=0
        
        str=string.format('${%s %s}',pt['name'],pt['arg'])
        str=conky_parse(str)
        
        value=tonumber(str)
        pct=value/pt['max']
        
        draw_ring(cr,pct,pt)
    end
    
    -- Check that Conky has been running for at least 5s

    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 updates=conky_parse('${updates}')
    update_num=tonumber(updates)
    
    if update_num>5 then
        for i in pairs(settings_table) do
            setup_rings(cr,settings_table[i])
        end
    end
    
    draw_clock_hands(cr,clock_x,clock_y)
end

Excuse me for my bad English is not my native language!
Thanks in advance!

Offline

#84 2014-03-03 13:51:18

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,287
Website

Re: HOW TO : using lua scripts in conky

tbk515 wrote:

Hi to all!
Is it possible?
I want to make chronograph watch. The clock background will be image from Conky, and I need only from watch hands.

Excuse me for my bad English is not my native language!
Thanks in advance!

Your English is fine.

What you want is already done.
2014_02_23_16_14_07_312x966_Sector11.jpg White.jpg The_S11_Clock_x4.jpg
circle and ring backgrounds done with draw-bg.lua


Code available two versions: Version One, Version Two and Version Two (2)

Last edited by Sector11 (2014-03-03 13:59:44)


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#85 2014-03-03 16:37:22

tbk515
New Member
From: Pld, BG, EU, EA, SS, MW
Registered: 2014-03-03
Posts: 2

Re: HOW TO : using lua scripts in conky

@Sector11, Thank you!
I appreciate your suggestions, but but I do not want the entire code!
I desire something like this:
2014_02_03_08_17_51_352x352_Sector11.jpg

but only the hands. How to edit my lua file to add 3 more hands?
Again, Thanks in advance!

Offline

#86 2014-03-03 18:04:05

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,287
Website

Re: HOW TO : using lua scripts in conky

tbk515 wrote:

@Sector11, Thank you!
I appreciate your suggestions, but but I do not want the entire code!
I desire something like this:
http://s20.postimg.org/r9enhqg0d/2014_0 … ctor11.jpg

but only the hands. How to edit my lua file to add 3 more hands?
Again, Thanks in advance!

I'm not lua literate .. I can't 'create' lua code ... I can tweak it though.  The original idea for the chronograph I came up with was because of mrpeachy's 4clocks.lua script.  The memory leak from the original clock.lua was plugged and it has 4 clocks in one script ... so there you are - 4 sets of hands.  The idea of changing them to day names, day numbers and month names came later.  When I showed you where the code was it was for you to look at and see how to do what you wanted.

Maybe looking at 4clocks.lua by mrpeachy will lead you in the right direction:
2014_03_03_14_34_57_612x162_Sector11.jpg
4clocks.lua

--[[multiple analogue clocks by mrpeachy - 18 Jun 2012
in conkyrc
lua_load /path/4clocks.lua
lua_draw_hook_pre main
TEXT
--]]

require 'cairo'

function conky_main()
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)
cr = cairo_create(cs)
--#########################################################################################################
--CLOCK SETTINGS
--set border options
clock_border_width=0
--set color and alpha for clock border
cbr,cbg,cbb,cba=1,1,1,1--full opaque white
--gap from clock border to hour marks
b_to_m=5
--set mark length
m_length=5
--set mark line width
m_width=2
--set mark line cap type
m_cap=CAIRO_LINE_CAP_ROUND
--set mark color and alpha,red blue green alpha
mr,mg,mb,ma=1,1,1,1--opaque white
--seconds hand setup
--set length of seconds hand
sh_length=50
--set hand width
sh_width=1
--set hand line cap
sh_cap=CAIRO_LINE_CAP_ROUND
--set seconds hand color
shr,shg,shb,sha=1,0,0,1--fully opaque red
--minues hand setup
--set length of minutes hand
mh_length=50
--set hand width
mh_width=2
--set hand line cap
mh_cap=CAIRO_LINE_CAP_ROUND
--set minute hand color
mhr,mhg,mhb,mha=1,1,1,1--fully opaque white
--hour hand setup
--set length of hour hand
hh_length=30
--set hand width
hh_width=2
--set hand line cap
hh_cap=CAIRO_LINE_CAP_ROUND
--set hour hand color
hhr,hhg,hhb,hha=1,1,1,1--fully opaque white


--CURRENT TIME
clock_radius=60
clock_centerx=100
clock_centery=75
--DRAWING CODE
--draw border
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
--draw marks
--stuff that can be moved outside of the loop, needs only be set once
--calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length
--set line cap type
cairo_set_line_cap  (cr, m_cap)
--set line width
cairo_set_line_width (cr,m_width)
--set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
--start for loop
for i=1,12 do
--drawing code uisng the value of i to calculate degrees
--calculate start point for 12 oclock mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
--calculate end point for 12 oclock mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--draw the line
cairo_stroke (cr)
end--of for loop
--[[ --time calculations###########################
hours=tonumber(os.date("%I"))--12 hour clock
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(os.date("%M"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(os.date("%S"))
]]
--time calculations ### not local ############
hours=tonumber(conky_parse("${tztime Canada/Pacific %l}"))
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(conky_parse("${tztime Canada/Pacific %M}"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(conky_parse("${tztime Canada/Pacific %S}"))
--draw hour hand ############################
--get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
--calculate degrees for the hand each second
hsec_degs=hsecs*(360/(60*60*12))--im using an equation instead of typing the calculation straight in because the result of 360/43200 gave us decimal places
--set radius we will use to calculate hand points
radius=hh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,hh_width)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
--draw minutes hand
--get minutes and seconds just as seconds
msecs=m_to_s+seconds
--calculate degrees for the hand each second
msec_degs=msecs*0.1
--set radius we will use to calculate hand points
radius=mh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,mh_width)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--draw seconds hand #############################
--calculate degrees for the hand each second
sec_degs=seconds*6
--set radius we will use to calculate hand points
radius=sh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes
cairo_set_line_width (cr,sh_width)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
--###################################################

--ALTERNATE TIME 1 ##################################
--CLOCK SETTINGS
clock_radius=60
clock_centerx=240
clock_centery=75
--DRAWING CODE
--draw border
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
--draw marks
--stuff that can be moved outside of the loop, needs only be set once
--calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length
--set line cap type
cairo_set_line_cap  (cr, m_cap)
--set line width
cairo_set_line_width (cr,m_width)
--set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
--start for loop
for i=1,12 do
--drawing code uisng the value of i to calculate degrees
--calculate start point for 12 oclock mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
--calculate end point for 12 oclock mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--draw the line
cairo_stroke (cr)
end--of for loop
--time calculations###########################
hours=tonumber(conky_parse("${tztime Canada/Central %l}"))
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(conky_parse("${tztime Canada/Central %M}"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(conky_parse("${tztime Canada/Central %S}"))
--draw hours hand ############################
--get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
--calculate degrees for the hand each second
hsec_degs=hsecs*(360/(60*60*12))--im using an equation instead of typing the calculation straight in because the result of 360/43200 gave us decimal places
--set radius we will use to calculate hand points
radius=hh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,hh_width)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
--draw minutes hand
--get minutes and seconds just as seconds
msecs=m_to_s+seconds
--calculate degrees for the hand each second
msec_degs=msecs*0.1
--set radius we will use to calculate hand points
radius=mh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,mh_width)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--draw seconds hand #############################
--calculate degrees for the hand each second
sec_degs=seconds*6
--set radius we will use to calculate hand points
radius=sh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes
cairo_set_line_width (cr,sh_width)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
--###################################################

--ALTERNATE TIME 2 ##################################
--CLOCK SETTINGS
clock_radius=60
clock_centerx=380
clock_centery=75
--DRAWING CODE
--draw border
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
--draw marks
--stuff that can be moved outside of the loop, needs only be set once
--calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length
--set line cap type
cairo_set_line_cap  (cr, m_cap)
--set line width
cairo_set_line_width (cr,m_width)
--set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
--start for loop
for i=1,12 do
--drawing code uisng the value of i to calculate degrees
--calculate start point for 12 oclock mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
--calculate end point for 12 oclock mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--draw the line
cairo_stroke (cr)
end--of for loop
--time calculations###########################
hours=tonumber(conky_parse("${tztime Canada/Atlantic %l}"))
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(conky_parse("${tztime Canada/Atlantic %M}"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(conky_parse("${tztime Canada/Atlantic %S}"))
--draw hours hand ############################
--get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
--calculate degrees for the hand each second
hsec_degs=hsecs*(360/(60*60*12))--im using an equation instead of typing the calculation straight in because the result of 360/43200 gave us decimal places
--set radius we will use to calculate hand points
radius=hh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,hh_width)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
--draw minutes hand
--get minutes and seconds just as seconds
msecs=m_to_s+seconds
--calculate degrees for the hand each second
msec_degs=msecs*0.1
--set radius we will use to calculate hand points
radius=mh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,mh_width)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--draw seconds hand #############################
--calculate degrees for the hand each second
sec_degs=seconds*6
--set radius we will use to calculate hand points
radius=sh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes
cairo_set_line_width (cr,sh_width)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
--###################################################

--ALTERNATE TIME 1 ##################################
--CLOCK SETTINGS
clock_radius=60
clock_centerx=520
clock_centery=75
--DRAWING CODE
--draw border
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
--draw marks
--stuff that can be moved outside of the loop, needs only be set once
--calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length
--set line cap type
cairo_set_line_cap  (cr, m_cap)
--set line width
cairo_set_line_width (cr,m_width)
--set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
--start for loop
for i=1,12 do
--drawing code uisng the value of i to calculate degrees
--calculate start point for 12 oclock mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
--calculate end point for 12 oclock mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--draw the line
cairo_stroke (cr)
end--of for loop
--time calculations###########################
hours=tonumber(conky_parse("${tztime GMT %l}"))
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(conky_parse("${tztime GMT %M}"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(conky_parse("${tztime GMT %S}"))
--draw hours hand ############################
--get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
--calculate degrees for the hand each second
hsec_degs=hsecs*(360/(60*60*12))--im using an equation instead of typing the calculation straight in because the result of 360/43200 gave us decimal places
--set radius we will use to calculate hand points
radius=hh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,hh_width)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
--draw minutes hand
--get minutes and seconds just as seconds
msecs=m_to_s+seconds
--calculate degrees for the hand each second
msec_degs=msecs*0.1
--set radius we will use to calculate hand points
radius=mh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,mh_width)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--draw seconds hand #############################
--calculate degrees for the hand each second
sec_degs=seconds*6
--set radius we will use to calculate hand points
radius=sh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes
cairo_set_line_width (cr,sh_width)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
--###################################################
--#########################################################################################################
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function

The code for the image you showed has a lot of comments added by me. The index is user friendly with 'highlight the line' and use find and was my 'development' lua script for the 22 versions I have of "the chronograph" lua script (various stages of development):
chrono_mix.lua

--[[ multiple analogue clocks by mrpeachy - 18 Jun 2012
 21 Jun 2012 - Chronograph modifications by Sector11
 22 Jun 2012 - again with mrpeachy's help day names, numbers and month names
 23 Jun 2012 - crono.lua by mrprachy - modified by Sector11 23/24 Jun 2012
 24 Jun 2012 - crono_mix - combination of Cronograph.lua and modified crono.lua

use in conkyrc

lua_load /path/crono_mix.lua
lua_draw_hook_pre main
TEXT

-- INDEX (use find with):

-- ###### 12 OR 24 CLOCK FACE
-- SET BORDER OPTIONS ######  ALL CLOCKS

-- ### START CLOCK A ######################################
-- MARKS AROUND CLOCK A -- Large Main 24 HR Clock
-- CLOCK A HOUR HAND
-- CLOCK A MINUTE HAND SETUP
-- CLOCK A SECOND HAND SETUP
-- CLOCK A ###### 24 HR TIME

-- ### START DIAL B ### Top - Week Day Names Dial #########
-- ### START DIAL C ### Right - Month Names Dial ##########
-- ### START DIAL D ### Left - Day Numbers Dial ###########

-- ### START CLOCK E ######################################
-- MARKS AROUND CLOCK E -- Bottom - 12 HR Clock
-- CLOCK E HOUR HAND
-- CLOCK E MINUTE HAND SETUP
-- CLOCK E SECOND HAND SETUP
-- CLOCK E ###### 12 HR TIME

TO GET MONTH NAME WHERE THE HOUR # IS FOR THAT MONTH
 mrpeachy wrote:

    the numbers are drawn using a for loop somewhere, like this

    for i=1,12 do
    calculate position of number
    move_to(x,y)
    show_text(i)
    end

    change it to something like this

    for i=1,12 do
    calculate position of number
      if i==month_number then
      move_to(x,y)
      show_text(month_number)
      else
      move_to(x,y)
      show_text(i)
      end
    end ]]


require 'cairo'

function conky_main()
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)
cr = cairo_create(cs)
local extents=cairo_text_extents_t:create()
tolua.takeownership(extents)
-- ### SETTINGS AREA ######################################
-- ###### 12 OR 24 CLOCK FACE #############################
local clock_type_A=24 -- Large Main 24 HR Clock
local clock_type_E=12 -- Bottom - 12 HR Clock

-- ###### CLOCK SETTINGS ##################################
-- SET BORDER OPTIONS FOR "CLOCKS" ########################
local clock_border_width=0
-- set color and alpha for clock border
local cbr,cbg,cbb,cba=1,1,1,1  -- full opaque white
-- gap from clock border to minute marks
local b_to_m=1

-- ########################################################
-- ### START CLOCK A ######################################
-- MARKS AROUND CLOCK A -- Large Main 24 HR Clock
local number_marks_A=24
-- set mark length
local m_length_A=0
-- set mark width
local m_width_A=0
-- set mark line cap type
local m_cap=CAIRO_LINE_CAP_ROUND
-- set mark color and alpha,red blue green alpha
local mr,mg,mb,ma=1,1,1,1-- opaque white
-- SETUP HOUR HANDS
-- CLOCK A HOUR HAND
-- set length of hour hand
hh_length_A=130
-- set hour hand width
hh_width_A=3
-- set hour hand line cap
hh_cap=CAIRO_LINE_CAP_ROUND
-- set hour hand color
hhr,hhg,hhb,hha=1,1,1,1-- fully opaque white
-- SETUP MINUTE HANDS
-- CLOCK A MINUTE HAND SETUP
-- set length of minute hand
mh_length_A=145
-- set minute hand width
mh_width_A=2
-- set minute hand line cap
mh_cap=CAIRO_LINE_CAP_ROUND
-- set minute hand color
mhr,mhg,mhb,mha=1,1,1,1-- fully opaque white
-- SETUP SECOND HANDS
-- CLOCK A SECOND HAND SETUP
-- set length of seconds hand
sh_length_A=160
-- set hour hand width
sh_width_A=1
-- set hour hand line cap
sh_cap=CAIRO_LINE_CAP_ROUND
-- set seconds hand color
shr,shg,shb,sha=1,0,0,1-- fully opaque red
-- CLOCK A ###### 24 HR TIME
-- CLOCK SETTINGS
clock_radius=200
clock_centerx=175
clock_centery=175
-- DRAWING CODE
-- DRAW BORDER
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
-- DRAW MARKS
-- stuff that can be moved outside of the loop, needs only be set once
-- calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length_A
-- set line cap type
cairo_set_line_cap  (cr, m_cap)
-- set line width
cairo_set_line_width (cr,m_width_A)
-- set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
-- START LOOP FOR HOUR MARKS
for i=1,number_marks_A do
-- drawing code using the value of i to calculate degrees
-- calculate start point for 12/24 hour mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*(360/number_marks_A))
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
-- calculate end point for 12/24 hour mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*(360/number_marks_A))
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- draw the line
cairo_stroke (cr)
end-- of for loop
-- HOUR MARKS
-- TIME CALCULATIONS CLOCK A
if clock_type_A==12 then
hours=tonumber(os.date("%I"))
-- convert hours to seconds
h_to_s=hours*60*60
elseif clock_type_A==24 then
hours=tonumber(os.date("%H"))
-- convert hours to seconds
h_to_s=hours*60*60
end
minutes=tonumber(os.date("%M"))
-- convert minutes to seconds
m_to_s=minutes*60
-- get current seconds
seconds=tonumber(os.date("%S"))
-- DRAW HOUR HAND
-- get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
-- calculate degrees for each second
hsec_degs=hsecs*(360/(60*60*clock_type_A))-- use equation ~ eliminate decimals
-- set radius to calculate hand points
radius=hh_length_A
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of hour hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes and draw line
cairo_set_line_width (cr,hh_width_A)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
-- DRAW MINUTE HAND
-- get minutes and seconds just as seconds
msecs=m_to_s+seconds
-- calculate degrees for each second
msec_degs=msecs*0.1
-- set radius to calculate hand points
radius=mh_length_A
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of minute hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes and draw line
cairo_set_line_width (cr,mh_width_A)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--[[ DRAW SECOND HAND
-- calculate degrees for each second
sec_degs=seconds*6
-- set radius to calculate hand points
radius=sh_length_A
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes
cairo_set_line_width (cr,sh_width_A)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr) ]]
-- POSITION FOR TEXT HOUR NUMBERS
local center_x=175
local center_y=175
local radius=160
-- FONT
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 10)
cairo_set_source_rgba (cr,1,1,1,1)
-- TABLE OF TEXT -- in order
text_days={"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23",}
for i=1,24 do
-- OUTTER POINTS POSTION FOR TEXT
local point=(math.pi/180)*((360/24)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
-- CALCULATE CENTRE OF TEXT
local text=text_days[i]--gets text from table
cairo_text_extents(cr,text,extents)
local width=extents.width
local height=extents.height
cairo_move_to(cr,center_x+x-(width/2),center_y+y+(height/2))
cairo_show_text (cr, text)
cairo_stroke (cr)
end
-- INNER POINTS POSITION, radius smaller than text circle
local radius=150
for i=1,24 do
local point=(math.pi/180)*((360/24)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
-- ### END CLOCK A ########################################

-- ########################################################
-- ### START DIAL B ### Top - Week Day Names Dial #########
-- days of week
-- positioning
local center_x=175
local center_y=95
local radius=50
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 10)
cairo_set_source_rgba (cr,1,1,1,1)
-- table holds text you want to see in order
text_days={"SUN","MON","TUE","WED","THR","FRI","SAT",}
-- draw days
local tx_deg=30
for i=1,7 do
start=((360/7)*(i-1))-(tx_deg/2)
circlewriting (text_days[i], "CorporateMonoExtraBold", 10, radius, center_x, center_y, {0xffffff,1}, start, start+tx_deg)
end
--draw points, radius smaller than text circle

local radius=45
for i=1,7 do
local point=(math.pi/180)*((360/7)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
--draw hand pointing to current day
local hand_length=40--radius for this calculation
local day_number=tonumber(os.date("%w"))
local point=(math.pi/180)*((360/7)*(day_number))
local x=0+hand_length*(math.sin(point))
local y=0-hand_length*(math.cos(point))
cairo_move_to (cr,center_x,center_y)
cairo_line_to (cr,center_x+x,center_y+y)
cairo_stroke (cr)
-- ### END CLOCK B ########################################

-- ########################################################
-- ### START DIAL C ### Right - Month Names Dial ##########
-- DIAL POSITION FOR TEXT
local center_x=260
local center_y=175
local radius=45
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 10)
cairo_set_source_rgba (cr,1,1,1,1)
-- table holds text you want to see in order
text_days={"DEC","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV",}
-- draw days
local tx_deg=20
for i=1,12 do
start=((360/12)*(i-1))-(tx_deg/2)
circlewriting (text_days[i], "CorporateMonoExtraBold", 10, radius, center_x, center_y, {0xffffff,1}, start, start+tx_deg)
end
--draw points, radius smaller than text circle

local radius=40
for i=1,12 do
local point=(math.pi/180)*((360/12)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
--draw hand pointing to current day
local hand_length=35 --radius for this calculation
local day_number=tonumber(os.date("%m"))
local point=(math.pi/180)*((360/12)*(day_number))
local x=0+hand_length*(math.sin(point))
local y=0-hand_length*(math.cos(point))
cairo_move_to (cr,center_x,center_y)
cairo_line_to (cr,center_x+x,center_y+y)
cairo_stroke (cr)
-- ### END CLOCK C ########################################

-- ### START DIAL D ### Left - Day Numbers Dial ###########
-- GET NUMBER OF DAYS IN CURRENT MONTH
-- calculate Feb, then set up table
year4num=os.date("%Y")
t1=os.time({year=year4num,month=03,day=01,hour=00,min=0,sec=0});
t2=os.time({year=year4num,month=02,day=01,hour=00,min=0,sec=0});
febdaynum=tonumber((os.difftime(t1,t2))/(24*60*60))
-- MONTH TABLE
monthdays={31,febdaynum,31,30,31,30,31,31,30,31,30,31}
this_month=tonumber(os.date("%m"))
number_days=monthdays[this_month]
-- TEXT positioning
local center_x=95
local center_y=175
local radius=50
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 8)
cairo_set_source_rgba (cr,1,1,1,1)
for i=1,number_days do
-- OUTTER POINTS POSTION FOR TEXT
local point=(math.pi/180)*((360/number_days)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
-- CALCULATE CENTRE OF TEXT
local text=i
cairo_text_extents(cr,text,extents)
local width=extents.width
local height=extents.height
cairo_move_to(cr,center_x+x-(width/2),center_y+y+(height/2))
cairo_show_text (cr, text)
cairo_stroke (cr)
end
-- INNER POINTS POSITION, radius smaller than text circle
local radius=40
for i=1,number_days do
local point=(math.pi/180)*((360/number_days)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
-- DRAW HAND -- snaps to current DAY
local this_day=tonumber(os.date("%d"))
local hand_length=35--radius for this calculation
local point=(math.pi/180)*((360/number_days)*(this_day-1))
local x=0+hand_length*(math.sin(point))
local y=0-hand_length*(math.cos(point))
cairo_move_to (cr,center_x,center_y)
cairo_line_to (cr,center_x+x,center_y+y)
cairo_stroke (cr)
-- ### END CLOCK D ########################################

-- ########################################################
-- ### START CLOCK E ######################################
-- MARKS AROUND CLOCK E -- Bottom - 12 HR Clock
local number_marks_E=12
-- set mark length
local m_length_E=0
-- set mark width
local m_width_E=0
-- set mark line cap type
local m_cap=CAIRO_LINE_CAP_ROUND
-- set mark color and alpha,red blue green alpha
local mr,mg,mb,ma=1,1,0,1-- opaque white
-- SETUP HOUR HAND
-- CLOCK E HOUR HAND
-- set length of hour hand
hh_length_E=22
-- set hour hand width
hh_width_E=4
-- set hour hand line cap
hh_cap=CAIRO_LINE_CAP_ROUND
-- set hour hand color
hhr,hhg,hhb,hha=0.3,  0.6,  0.9  ,1 -- fully opaque lightblue
-- SETUP MINUTE HAND
-- CLOCK E MINUTE HAND SETUP
-- set length of minute hand
mh_length_E=37
-- set minute hand width
mh_width_E=2
-- set minute hand line cap
mh_cap=CAIRO_LINE_CAP_ROUND
-- set minute hand color
mhr,mhg,mhb,mha=0.0,  0.6,  0.9  ,1 -- fully opaque lightblue
-- SETUP SECOND HAND
-- CLOCK E SECOND HAND SETUP
-- set length of seconds hand
sh_length_E=40
-- set hour hand width
sh_width_E=1
-- set hour hand line cap
sh_cap=CAIRO_LINE_CAP_ROUND
-- set seconds hand color
shr,shg,shb,sha=1,0,0,1 -- fully opaque red
-- CLOCK E ###### 12 HR TIME
-- CLOCK SETTINGS
clock_radius=45
clock_centerx=175
clock_centery=260
-- DRAWING CODE
-- DRAW BORDER
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
-- DRAW MARKS
-- stuff that can be moved outside of the loop, needs only be set once
-- calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length_E
-- set line cap type
cairo_set_line_cap  (cr, m_cap)
-- set line width
cairo_set_line_width (cr,m_width_E)
-- set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
-- START LOOP FOR SECOND MARKS
for i=1,number_marks_E do
-- drawing code using the value of i to calculate degrees
-- calculate start point for 12/24 hour mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*(360/number_marks_E))
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
-- calculate end point for 12/24 hour mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*(360/number_marks_E))
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- draw the line
cairo_stroke (cr)
end-- of for loop
-- TIME CALCULATIONS CLOCK E
if clock_type_E==12 then
hours=tonumber(os.date("%I"))
-- convert hours to seconds
h_to_s=hours*60*60
elseif clock_type_E==24 then
hours=tonumber(os.date("%H"))
-- convert hours to seconds
h_to_s=hours*60*60
end
minutes=tonumber(os.date("%M"))
-- convert minutes to seconds
m_to_s=minutes*60
-- get current seconds
seconds=tonumber(os.date("%S"))
-- DRAW HOUR HAND
-- get hours minutes seconds as just seconds and draw it
hsecs=h_to_s+m_to_s+seconds
-- calculate degrees for each second
hsec_degs=hsecs*(360/(60*60*clock_type_E))-- use equation ~ eliminate decimals
-- set radius to calculate hand points
radius=hh_length_E
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of minute hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes and draw line
cairo_set_line_width (cr,hh_width_E)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
-- DRAW MINUTE HAND
-- get minutes and seconds as seconds
msecs=m_to_s+seconds
-- calculate degrees for each second
msec_degs=msecs*0.1
-- set radius to calculate hand points
radius=mh_length_E
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of minute hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes and draw line
cairo_set_line_width (cr,mh_width_E)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
-- DRAW SECOND HAND
-- calculate degrees for each second
sec_degs=seconds*6
-- set radius to calculate hand points
radius=sh_length_E
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes
cairo_set_line_width (cr,sh_width_E)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
-- POSITION FOR TEXT HOUR NUMBERS
local center_x=175
local center_y=260
local radius=45
-- FONT
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 10)
cairo_set_source_rgba (cr,1,1,1,1)
-- TABLE OF TEXT -- in order
--text_days={"12","01","02","03","04","05","06","07","08","09","10","11",}
-- FOR A 12 HOUR CLOCK WITH THE NUMBERS 13-00
text_days={"00","13","14","15","16","17","18","19","20","21","22","23",}
for i=1,12 do
-- OUTTER POINTS POSTION FOR TEXT
local point=(math.pi/180)*((360/12)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
-- CALCULATE CENTRE OF TEXT
local text=text_days[i]--gets text from table
cairo_text_extents(cr,text,extents)
local width=extents.width
local height=extents.height
cairo_move_to(cr,center_x+x-(width/2),center_y+y+(height/2))
cairo_show_text (cr, text)
cairo_stroke (cr)
end
-- INNER POINTS POSITION, radius smaller than text circle
local radius=32
for i=1,12 do
local point=(math.pi/180)*((360/12)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
-- ### END CLOCK E ########################################

-- ########################################################
end-- end main function

function circlewriting(text, font, fsize, radi, horiz, verti, text_color, start, finish)
local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255, ((col_a[1] / 0x100) % 0x100) / 255, (col_a[1] % 0x100) / 255, col_a[2]
end
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fsize)
cairo_set_source_rgba (cr,rgb_to_r_g_b(text_color));
local inum=string.len(text)
local deg=(finish-start)/(inum)
local r2d=(math.pi/180)
	for i=1,inum do
	local cha=string.sub(text,i,i)
	local interval=(r2d*(start+(deg*(i-1))))
	local txs=0+radi*(math.sin(interval))
	local tys=0-radi*(math.cos(interval))
	cairo_move_to (cr, txs+horiz, tys+verti);
	cairo_rotate (cr, interval)
	cairo_show_text (cr, cha)
	cairo_stroke (cr)
	cairo_rotate (cr, -interval)
	end
end--of function

Basically for each set of hands you need a new complete "function" for each 'clock', not just hands ...

Last edited by Sector11 (2014-03-03 18:07:57)


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#87 2014-03-03 20:38:10

dk75
#! Junkie
Registered: 2012-06-14
Posts: 250

Re: HOW TO : using lua scripts in conky

That's why moving every small part to separate functions is better.
If you have one function to calculate time, one function to calculate angle of hand for set time and function to draw hand as separate, you can reuse it for as much as you need.

My 2 cents.  devil


Debian Sid (Minted) x86_64/3.12-10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Intel X3100
Lenovo T61, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
Linux user No.: 483055 | Conky Pitstop

Offline

#88 2014-03-03 22:43:30

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

dk75 wrote:

That's why moving every small part to separate functions is better.
If you have one function to calculate time, one function to calculate angle of hand for set time and function to draw hand as separate, you can reuse it for as much as you need.

My 2 cents.  devil

this is indeed true big_smile

for me, doing the code in one large block or distributing the parts to functions depends on the complexity and purpose of the script...
while writing i typically write in a block, then when i see bits of the script that i am re using i move them to their own functions

but if a piece of code is a demonstration of principle, ie can i do this... oh look i can!
then it typically doesn't make it to the function distribution stage devil

Offline

#89 2014-03-03 22:54:29

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,287
Website

Re: HOW TO : using lua scripts in conky

... and along comes a lua illiterate user, namely one Sector11, and I just use what I get my hands on ... tweaking the highly obvious. lol

If it works ... why fix it?  Just my 2½¢ worth.

Last edited by Sector11 (2014-03-03 22:55:44)


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo