Code:
--[[ circleweather by mrpeachy may 2011 - weather image version
kudos to Sector11 who gave me the push to do this and whose weather code is my reference
call in conkyrc like this, but change to whatever you saved it as and where
lua_load /home/mcdowall/lua/cweather.lua
lua_draw_hook_pre draw_fig
]]
require 'cairo'
require 'imlib2'
function string:split(delimiter)
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end
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
--#########################################################################################################
--#########################################################################################################
--get weather data
time=1800
timer=(updates % time)+1
if updates==10 or timer==1 then
filenow=conky_parse("${exec conkyForecast -d WI}")
filed1=conky_parse("${exec conkyForecast -d WI -s 1}")
filed2=conky_parse("${exec conkyForecast -d WI -s 2}")
filed3=conky_parse("${exec conkyForecast -d WI -s 3}")
filed4=conky_parse("${exec conkyForecast -d WI -s 4}")
filed5=conky_parse("${exec conkyForecast -d WI -s 5}")
--now current conditions
nowcc=conky_parse("${exec conkyForecast -d CT}")
--forcast days text--if font/size is changed, must be changed here also
font="White Rabbit"
fontsize=14
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fontsize);
day1n=conky_parse("${exec conkyForecast -d DW -s 1 -w}")
day2n=conky_parse("${exec conkyForecast -d DW -s 2 -w}")
day3n=conky_parse("${exec conkyForecast -d DW -s 3 -w}")
day4n=conky_parse("${exec conkyForecast -d DW -s 4 -w}")
day5n=conky_parse("${exec conkyForecast -d DW -s 5 -w}")
text=string.upper(day5n)
extents=cairo_text_extents_t:create()
textoriginal=text
cairo_text_extents(cr,text,extents)
dayn_w=extents.width
dayn_h=extents.height
--highs and lows
font="Mono"
fontsize=10
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fontsize);
day5h=conky_parse("${exec conkyForecast -d HT -s 5 -i}")
text=string.upper(day5h)
extents=cairo_text_extents_t:create()
textoriginal=text
cairo_text_extents(cr,text,extents)
dayh_h=extents.height
------------------------------------------
day5l=conky_parse("${exec conkyForecast -d LT -s 5 -i}")
day4h=conky_parse("${exec conkyForecast -d HT -s 4 -i}")
day4l=conky_parse("${exec conkyForecast -d LT -s 4 -i}")
day3h=conky_parse("${exec conkyForecast -d HT -s 3 -i}")
day3l=conky_parse("${exec conkyForecast -d LT -s 3 -i}")
day2h=conky_parse("${exec conkyForecast -d HT -s 2 -i}")
day2l=conky_parse("${exec conkyForecast -d LT -s 2 -i}")
day1h=conky_parse("${exec conkyForecast -d HT -s 1 -i}")
day1l=conky_parse("${exec conkyForecast -d LT -s 1 -i}")
end --weather gathering
--######################################
--center position
--background
bgrad=145--radius
--center position
cx,cy=200,bgrad
-----------------
cairo_set_source_rgba (cr,0,0,0,0.3)--color for background
----------------------------------------------------------
cairo_arc (cr,cx,cy,bgrad,((2*math.pi)/4)*1,((2*math.pi)/4)*3)
dist1=conky_window.width-cx
cairo_rel_line_to (cr,dist1,0)
cairo_rel_line_to (cr,0,bgrad*2)
cairo_rel_line_to (cr,-dist1,0)
cairo_fill(cr)
--PRINT CURRENT CONDITIONS--------------------------------
crad=80
length=string.len(nowcc)
angs=-155
angt=125
lenmax=string.len("Scattered Thunderstorms")
angadd=(angt/lenmax)*length
angf=angs+angadd
circlewriting(string.upper(nowcc),"White Rabbit",12,crad,cx,cy,1,1,1,1,angs,angf,0)
crad=95
circlewriting("CURRENT CONDITIONS","White Rabbit",12,crad,cx,cy,1,1,1,1,angs,angs+angt,0)
------------------------------------------
--WEATHER IMAGES--------------------------
set={file=filenow,cx=cx,cy=cy,xscale=1,yscale=1,radius=0,angle=0};image(set)
set={file=filed1,cx=cx,cy=cy,xscale=1.75,yscale=1.75,radius=80,angle=0};image(set)
set={file=filed2,cx=cx,cy=cy,xscale=1.75,yscale=1.75,radius=80,angle=45};image(set)
set={file=filed3,cx=cx,cy=cy,xscale=1.75,yscale=1.75,radius=80,angle=90};image(set)
set={file=filed4,cx=cx,cy=cy,xscale=1.75,yscale=1.75,radius=80,angle=135};image(set)
set={file=filed5,cx=cx,cy=cy,xscale=1.75,yscale=1.75,radius=80,angle=180};image(set)
-------------------------------------------
--test circle for positioning
--cairo_set_source_rgba (cr,1,1,1,1)
--cairo_set_line_width (cr,1)
--cairo_arc (cr,cx,cy,120,0,2*math.pi)
--cairo_stroke (cr)
--FORECAST TEXT
--heading
circlewriting("FORECAST","White Rabbit",12,110,cx,cy,1,1,1,1,-90,-20,0)
--day and high low text
--set radius for text
local tradius=120
--set gap between day name and temps
local gap=4
--set font, size and color for day names
local dayfont="White Rabbit"
local dayfontsize=14
local dtr,dtg,dtb,dta=1,1,1,1
--set font, size and color for high|low temps
local hilofont="Mono"
local hilofontsize=10
local htr,htg,htb,hta=1,1,1,1
--height of text
nheight=dayn_h
hlheight=dayh_h
------------------------------------
--angle of display is set below for each text instance
------------------------------------
--forecast day 1
set={angle=0,
dayname=string.upper(day1n),dayfont=dayfont,dayfontsize=dayfontsize,dtr=dtr,dtg=dtg,dtb=dtb,dta=dta,
hilo=string.upper(day1h) .. "|" .. string.upper(day1l),hilofont=hilofont,hilofontsize=hilofontsize,htr=htr,htg=htg,htb=htb,hta=hta,
cx=cx,cy=cy,gap=gap,radius=tradius,nheight=nheight,hlheight=hlheight,
};wtext(set)
--forecast day 2
set={angle=45,
dayname=string.upper(day2n),dayfont=dayfont,dayfontsize=dayfontsize,dtr=dtr,dtg=dtg,dtb=dtb,dta=dta,
hilo=string.upper(day2h) .. "|" .. string.upper(day2l),hilofont=hilofont,hilofontsize=hilofontsize,htr=htr,htg=htg,htb=htb,hta=hta,
cx=cx,cy=cy,gap=gap,radius=tradius,nheight=nheight,hlheight=hlheight,
};wtext(set)
--forecast day 3
set={angle=90,
dayname=string.upper(day3n),dayfont=dayfont,dayfontsize=dayfontsize,dtr=dtr,dtg=dtg,dtb=dtb,dta=dta,
hilo=string.upper(day3h) .. "|" .. string.upper(day3l),hilofont=hilofont,hilofontsize=hilofontsize,htr=htr,htg=htg,htb=htb,hta=hta,
cx=cx,cy=cy,gap=gap,radius=tradius,nheight=nheight,hlheight=hlheight,
};wtext(set)
--forecast day 4
set={angle=135,
dayname=string.upper(day4n),dayfont=dayfont,dayfontsize=dayfontsize,dtr=dtr,dtg=dtg,dtb=dtb,dta=dta,
hilo=string.upper(day4h) .. "|" .. string.upper(day4l),hilofont=hilofont,hilofontsize=hilofontsize,htr=htr,htg=htg,htb=htb,hta=hta,
cx=cx,cy=cy,gap=gap,radius=tradius,nheight=nheight,hlheight=hlheight,
};wtext(set)
--forecast day 5
set={angle=180,
dayname=string.upper(day5n),dayfont=dayfont,dayfontsize=dayfontsize,dtr=dtr,dtg=dtg,dtb=dtb,dta=dta,
hilo=string.upper(day5h) .. "|" .. string.upper(day5l),hilofont=hilofont,hilofontsize=hilofontsize,htr=htr,htg=htg,htb=htb,hta=hta,
cx=cx,cy=cy,gap=gap,radius=tradius,nheight=nheight,hlheight=hlheight,
};wtext(set)
--#########################################################################################################
--#########################################################################################################
end-- if updates>5
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function
function circlewriting(text, font, fsize, radi, horiz, verti, tred, tgreen, tblue, talpha, start, finish, var1)
local inum=string.len(text)
range=finish
deg=(finish-start)/(inum-1)
degrads=1*(math.pi/180)
local textcut=string.gsub(text, ".", "%1@")
texttable=string.split(textcut, "@")
for i = 1,inum do
ival=i
interval=(degrads*(start+(deg*(i-1))))+var1
interval2=degrads*(start+(deg*(i-1)))
txs=0+radi*(math.sin(interval))
tys=0-radi*(math.cos(interval))
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, tred, tgreen, tblue, talpha);
cairo_move_to (cr, txs+horiz, tys+verti);
cairo_rotate (cr, interval2)
cairo_show_text (cr, (texttable[i]))
cairo_stroke (cr)
cairo_rotate (cr, -interval2)
end
end
function image(t)
local crad=t.radius
local d1w_ang=t.angle
local cx,cy=t.cx,t.cy
local filed1=t.file
local xscale=t.xscale
local yscale=t.yscale
d1warc=((2*math.pi)/(360))*d1w_ang
d1wx=0+crad*(math.sin(d1warc))
d1wy=0-crad*(math.cos(d1warc))
--images--------------------------
show = imlib_load_image(filed1)
if show == nil then return end
imlib_context_set_image(show)
w_img, h_img = imlib_image_get_width(), imlib_image_get_height()
width=w_img/xscale
height=h_img/yscale
iacross=cx-(width/2)+d1wx
idown=cy-(height/2)+d1wy
imlib_context_set_image(show)
scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), width, height)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(iacross, idown)
imlib_free_image()
end
function wtext(t)
local crad=t.radius
local gap=t.gap
local d1w_ang=t.angle
local font1=t.dayfont
local fontsize1=t.dayfontsize
local dayname=t.dayname
local font2=t.hilofont
local fontsize2=t.hilofontsize
local hilo=t.hilo
local dtr=t.dtr
local dtg=t.dtg
local dtb=t.dtb
local dta=t.dta
local htr=t.htr
local htg=t.htg
local htb=t.htb
local hta=t.htb
local nheight=t.nheight
local hlheight=t.hlheight
height=(nheight+hlheight+gap)/2
nadj=height-nheight
hladj=height-nadj
d1warc=((2*math.pi)/(360))*d1w_ang
d1wx=0+crad*(math.sin(d1warc))
d1wy=0-crad*(math.cos(d1warc))
cairo_select_font_face (cr, font1, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fontsize1);
cairo_move_to (cr,cx+d1wx,cy+d1wy-(nadj))
cairo_set_source_rgba (cr,dtr,dtg,dtb,dta)
cairo_show_text (cr,dayname)
cairo_stroke (cr)
--high low
cairo_select_font_face (cr, font2, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fontsize2);
cairo_move_to (cr,cx+d1wx,cy+d1wy+(hladj))
cairo_set_source_rgba (cr,htr,htg,htb,hta)
cairo_show_text (cr,hilo)
cairo_stroke (cr)
end
you will probably get this error in the console 4 times
Bookmarks