Code:
--lua calendar script by mrpeachy Feb 2011
--version2.1 with background and glassy effect overlay, background and overlay adjust when calendar gains a line due to month length and start day
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 -- starts the display
--####################################################################################################
--####################################################################################################
--title text color
tred,tgreen,tblue,talpha=0.9,0,0.3,1
--title text font
tfont="URW Gothic L"
--title text size
tfontsize=22
--###################################################
--main body text color
bred,bgreen,bblue,balpha=0.6,1,0.6,1
--main body text font
mfont="URW Gothic L"
--main body text size
mfontsize=18
--###################################################
--highlight text color
hred,hgreen,hblue,halpha=1,1,0.2,1
--highlight font
hfont="URW Gothic L"
--highlight size
hfontsize=24
--###################################################
--surrounding numbers (previous and next month) 1=on, 0=off
surround=1
--surrounding dates text color
sred,sgreen,sblue,salpha=0.3,0.5,0.3,1
--surrounding font
sfont="URW Gothic L"
--surounding size
sfontsize=18
--###################################################
--indicator box enter 1 for box or 0 for no box
box=1
--use the following 2 numbers to adjust box position
xadjust=2.5
yadjust=4
--set the box dimensions
width=34
height=23
--box color
xred,xgreen,xblue,xalpha=1,0.2,0.8,1
--##################################################
--position
across=55.5
down=65.5
--rotate - this will require repositioning above
rotate=0
--###################################################
--horizontal gap between dates
gaph=45
--###################################################
--gap between day titles and first line
gapt=30
--###################################################
--gap between calendar line
gapl=30
--###################################################
--spacer -- this can help with alignment enter 0, 1 space or 2 spaces between the ""
spacer=""
--###################################################
--start day, enter 0 for sunday, 1 for monday
sday=0
--###################################################
--## END OF CALENDAR SETUP ##########################
--###################################################
--calendar calcs
year=os.date("%G")
today=tonumber(os.date("%d"))
t1 = os.time( { year=year,month=03,day=01,hour=00,min=0,sec=0} );
t2 = os.time( { year=year,month=02,day=01,hour=00,min=0,sec=0} );
feb=(os.difftime(t1,t2))/(24*60*60)
local monthdays={ 31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
local day=tonumber(os.date("%w"))+1-sday
local day_num = today
local remainder=day_num % 7
start_day=day-(day_num % 7)
if start_day<0 then start_day=7+start_day end
month=os.date("%m")
mdays=monthdays[tonumber(month)]
mdaystm=mdays
x=mdays+start_day
dnum={}
dnumh={}
if mdays+start_day<36 then
dlen=35
plen=29
else
dlen=42
plen=36
end
for i=1,dlen do
if i<=start_day then dnum[i]=" "
else dn=i-start_day
if dn=="nil" then dn=0 end
if dn<=9 then dn=(spacer .. dn) end
if i>x then dn="" end
dnum[i]=dn
dnumh[i]=dn
if dn==(spacer .. today) or dn==today then
dnum[i]=""
end
if dn==(spacer .. today) or dn==today then
dnumh[i]=dn
place=i
else dnumh[i]=" "
end
end
end--for
--###################################################
--glassy look box drawer
-- if combined with another lua script this setup sections
-- needs to be at the start of the main function so that background doesn't cover the display
--set top left coordinates for box
glass_x,glass_y=across-25,down-35
--set box width
glass_w=355
--compensate for changing calendar height
if mdays+start_day<36 then
--height of 5 line calendar
glass_h=210
else
--height of 6 line calendar
glass_h=245
end
--set box corner radius
glass_cr=15
--set box corner radius
glass_cr=45
--######################################################
--set how far down the right side for the curve to start
glass_cs=45
--set how far down the left side for the curve to end
glass_ce=glass_h-45
--######################################################
--NOTE to have main curve start on box corner curve set on_curve to 1, else 0
on_curve=1
--set degrees around corner for main curve to start (0 to 90)
on_curvedeg=60
--######################################################
--set gradient colors
--start gradient
glass_sr,glass_sg,glass_sb,glass_sa=0,0,0,0
--end graient
glass_er,glass_eg,glass_eb,glass_ea=1,1,1,0.4
--control curve with these settings
--turn setting displaglass_y on = 1, off =0
displaglass_y=0
--point 1 -- display red circle
glass_angle1=270
glass_length1=glass_w/1.5--should be less than width
--point 2 -- display blue circle
glass_angle2=0
glass_length2=glass_h/1.5--should be less than height
--adjust the gradient - a number 1 or just over
glass_adjust=1.4
--end of setup ###################################################################
--draw background
--set background color
glass_bgr,glass_bgg,glass_bgb,glass_bga=0,0,0,1--46/255,46/255,3/255,1
--set start position for box - topleft corner
x=glass_x
y=glass_y
--set radius of corners
r=glass_cr
--set height and width of box
h=glass_h
w=glass_w
--calculations below
xtl=x+r
ytl=y+r
xtr=(x+r)+((w)-2*r)
ytr=y+r
xbr=(x+r)+((w)-2*r)
ybr=(y+r)+((h)-2*r)
xbl=(x+r)
ybl=(y+r)+((h)-2*r)
cairo_set_source_rgba (cr,glass_bgr,glass_bgg,glass_bgb,glass_bga)
cairo_move_to (cr,xtl,ytl-r)
cairo_line_to (cr,xtr,ytr-r)
cairo_arc(cr,xtr,ytr,r,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+r,ybr)
cairo_arc(cr,xbr,ybr,r,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+r)
cairo_arc(cr,xbl,ybl,r,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-r,ytl)
cairo_arc(cr,xtl,ytl,r,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_fill (cr)
--###################################################
cairo_rotate (cr,(math.pi/180)*(rotate))
--print calendar titles
--###################################################
cairo_select_font_face (cr, tfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, tfontsize);
cairo_set_source_rgba (cr,tred,tgreen,tblue,talpha)
if sday==0 then
dys={"SU","MO","TU","WE","TH","FR","SA"}
else
dys={"MO","TU","WE","TH","FR","SA","SU"}
end
--------------------------------
--use these settings to mess around with positioning
turn=0
ta=0
move=0
rot=0
--------------------------------
for i=1,7 do
cairo_move_to (cr, across+(gaph*(i-1)), down+(i*move))
cairo_rotate (cr,(math.pi/180)*(rot))
cairo_show_text (cr, dys[i])
cairo_stroke (cr)
cairo_rotate (cr,(math.pi/180)*(rot*-1))
end
cairo_select_font_face (cr, mfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, mfontsize);
cairo_set_source_rgba (cr,bred,bgreen,bblue,balpha)
for i=1,plen,7 do
fn=i
for i=fn,fn+6 do
cairo_move_to (cr, across+(gaph*(i-fn))-((((fn-1)/7)+ta)*turn), (i*move)+down+gapt+(gapl*((fn-1)/7)))
cairo_rotate (cr,(math.pi/180)*(rot))
cairo_show_text (cr, dnum[i])
cairo_stroke (cr)
cairo_rotate (cr,(math.pi/180)*(rot*-1))
end
end
cairo_select_font_face (cr, hfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, hfontsize);
cairo_set_source_rgba (cr,hred,hgreen,hblue,halpha)
for i=1,plen,7 do
fn=i
for i=fn,fn+6 do
cairo_move_to (cr, across+(gaph*(i-fn))-((((fn-1)/7)+ta)*turn), (i*move)+down+gapt+(gapl*((fn-1)/7)))
cairo_rotate (cr,(math.pi/180)*(rot))
cairo_show_text (cr, dnumh[i])
cairo_stroke (cr)
cairo_rotate (cr,(math.pi/180)*(rot*-1))
end
end
--###############################################################################
if surround==1 then
thisstart=tonumber(start_day)+1
thisend=tonumber(start_day)+mdays
previous=tonumber(start_day)
nextmon=dlen-thisend
pmon=tonumber(month)-1
if pmon==0 then pmon=12 end
pmon=monthdays[pmon]
snum={}
for i=1,dlen do
snum[i]=""
end
for i=tonumber(thisend)+1,tonumber(thisend)+nextmon do
snum[i]=i-tonumber(thisend)
end
for i=1,previous do
snum[i]=pmon-(previous-(i))
end
cairo_select_font_face (cr, sfont, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, sfontsize);
cairo_set_source_rgba (cr,sred,sgreen,sblue,salpha)
for i=1,plen,7 do
fn=i
for i=fn,fn+6 do
cairo_move_to (cr, across+(gaph*(i-fn))-((((fn-1)/7)+ta)*turn), (i*move)+down+gapt+(gapl*((fn-1)/7)))
cairo_rotate (cr,(math.pi/180)*(rot))
cairo_show_text (cr, snum[i])
cairo_stroke (cr)
cairo_rotate (cr,(math.pi/180)*(rot*-1))
end
end
end
--box aound
if box==1 then
cairo_set_source_rgba (cr,xred,xgreen,xblue,xalpha)
cairo_set_line_width (cr,1)
if place>0 and place<8 then
cy=down+gapt
elseif
place>7 and place<15 then
cy=down+gapt+gapl
elseif
place>13 and place<23 then
cy=down+gapt+gapl+gapl
elseif
place>21 and place<29 then
cy=down+gapt+gapl+gapl+gapl
elseif
place>28 and place<36 then
cy=down+gapt+gapl+gapl+gapl+gapl
end
placey=place %7
if placey==1 then
cx=across
elseif
placey==2 then
cx=across+(gaph*1)
elseif
placey==3 then
cx=across+(gaph*2)
elseif
placey==4 then
cx=across+(gaph*3)
elseif
placey==5 then
cx=across+(gaph*4)
elseif
placey==6 then
cx=across+(gaph*5)
elseif
placey==0 then
cx=across+(gaph*6)
end
cairo_rectangle (cr,cx-xadjust,cy+yadjust,width,-height)
cairo_stroke (cr)
end
--###################################################
cairo_rotate (cr,(math.pi/180)*(rotate*-1))
--end of calendar
--###################################################
--call drawing function ##########################################################
-- if combined with another lua script the call to the drawing function
-- needs to be at the end of the main function so that the effect covers the display
glass(glass_x,glass_y,glass_h,glass_w,glass_cs,glass_ce,glass_sr,glass_sg,glass_sb,glass_sa,glass_er,glass_eg,glass_eb,glass_ea,displaglass_y,glass_angle1,glass_length1,glass_angle2,glass_length2,glass_adjust,on_curve,on_curvedeg)
----------------------------------------------------------------
--#################################################################################
end--end if 5
end--end main function
--glassy drawing function put this after the main function
function glass(glass_x,glass_y,glass_h,glass_w,glass_cs,glass_ce,glass_sr,glass_sg,glass_sb,glass_sa,glass_er,glass_eg,glass_eb,glass_ea,displaglass_y,glass_angle1,glass_length1,glass_angle2,glass_length2,glass_adjust,on_curve,on_curvedeg)
--set start position for box - topleft corner
x=glass_x
y=glass_y
--set radius of corners
r=glass_cr
--set height and width of box
h=glass_h
w=glass_w
--calculations below
xtl=x+r
ytl=y+r
xtr=(x+r)+((w)-2*r)
ytr=y+r
xbr=(x+r)+((w)-2*r)
ybr=(y+r)+((h)-2*r)
xbl=(x+r)
ybl=(y+r)+((h)-2*r)
if on_curve==0 then
startglass_x=glass_x+glass_w
startglass_y=glass_y+glass_cs
else
rad=glass_cr
arc=((2*math.pi)/360)*(on_curvedeg)
oncurve_x=0+rad*(math.sin(arc))
oncurve_y=0-rad*(math.cos(arc))
startglass_x=oncurve_x+xtr
startglass_y=oncurve_y+ytr
end
endglass_x=glass_x
endglass_y=glass_y+glass_ce--
rad=glass_length1
arc=((2*math.pi)/360)*(glass_angle1)
c1glass_x=0+rad*(math.sin(arc))
c1glass_y=0-rad*(math.cos(arc))
glass_center1glass_x=c1glass_x+startglass_x
glass_center1glass_y=c1glass_y+startglass_y
rad=glass_length2
arc=((2*math.pi)/360)*(glass_angle2)
c2glass_x=0+rad*(math.sin(arc))
c2glass_y=0-rad*(math.cos(arc))
glass_center2glass_x=c2glass_x+endglass_x
glass_center2glass_y=c2glass_y+endglass_y
if displaglass_y==1 then
cairo_set_line_width (cr,1)----------------------
cairo_set_source_rgba (cr,1,0,1,1)---------------
cairo_move_to (cr,startglass_x,startglass_y)-----------------
cairo_line_to (cr,glass_center1glass_x,glass_center1glass_y)-------------
cairo_stroke (cr)--------------------------------
cairo_set_source_rgba (cr,1,0,0,1)---------------
cairo_arc (cr,startglass_x,startglass_y,3,0,2*math.pi)-------
cairo_fill (cr)----------------------------------
cairo_set_source_rgba (cr,1,0,0,1)---------------
cairo_arc (cr,startglass_x,startglass_y,glass_length1,0,2*math.pi)
cairo_stroke (cr)--------------------------------
cairo_set_source_rgba (cr,0,1,0,1)---------------
cairo_arc (cr,glass_center1glass_x,glass_center1glass_y,3,0,2*math.pi)---
cairo_fill (cr)----------------------------------
cairo_set_source_rgba (cr,1,0,1,1)---------------
cairo_move_to (cr,endglass_x,endglass_y)---------------------
cairo_line_to (cr,glass_center2glass_x,glass_center2glass_y)-------------
cairo_stroke (cr)--------------------------------
cairo_set_source_rgba (cr,0,1,1,1)---------------
cairo_arc (cr,endglass_x,endglass_y,3,0,2*math.pi)-----------
cairo_fill (cr)----------------------------------
cairo_arc (cr,endglass_x,endglass_y,glass_length2,0,2*math.pi)-----
cairo_stroke (cr)--------------------------------
cairo_set_source_rgba (cr,1,1,0,1)---------------
cairo_arc (cr,glass_center2glass_x,glass_center2glass_y,3,0,2*math.pi)---
cairo_fill (cr)----------------------------------
end
if glass_w>glass_h then
cc=glass_w
else
cc=glass_h
end
ccglass_x=glass_x+cc
ccglass_y=glass_y+cc
pat = cairo_pattern_create_radial (ccglass_x,ccglass_y, 1,
ccglass_x,ccglass_y, cc*glass_adjust);
cairo_pattern_add_color_stop_rgba (pat, 1,glass_er,glass_eg,glass_eb,glass_ea);
cairo_pattern_add_color_stop_rgba (pat, 0,glass_sr,glass_sg,glass_sb,glass_sa);
cairo_set_source (cr,pat)
cairo_set_line_width (cr,1)
if on_curve==0 then
cairo_move_to (cr,xtl,ytl-r)
cairo_line_to (cr,xtr,ytr-r)
cairo_arc(cr,xtr,ytr,r,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,glass_x+glass_w,glass_y+glass_cs)
cairo_curve_to (cr,glass_center1glass_x,glass_center1glass_y,glass_center2glass_x,glass_center2glass_y,endglass_x,endglass_y)
cairo_line_to (cr,xtl-r,ytl)
cairo_arc(cr,xtl,ytl,r,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_fill (cr)
else
cairo_move_to (cr,xtl,ytl-r)
cairo_line_to (cr,xtr,ytr-r)
cairo_arc(cr,xtr,ytr,r,((math.pi/180)*-90),((math.pi/180)*(on_curvedeg-90)))
cairo_curve_to (cr,glass_center1glass_x,glass_center1glass_y,glass_center2glass_x,glass_center2glass_y,endglass_x,endglass_y)
cairo_line_to (cr,xtl-r,ytl)
cairo_arc(cr,xtl,ytl,r,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_fill (cr)
end
end
400 lines of lua code may be a bit overkill for a calendar... but oh well... i think it looks good
there is a bug that will occur if the calendar gains a line when a month starts on a day late in the week, need to make the background and overlay change to compensate
Bookmarks