Saturday, February 6, 2010

flower.lua
--[[valentine flowers by mrpeachy (2010)]]
require 'cairo'
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 circlewriting(text, char, font, fsize, radi, horiz, verti, tred, tgreen, tblue, talpha, variable)
local textcut=string.gsub(text, ".", "%1@@@")
texttable=string.split(textcut, "@@@")
for i=1,char do
--calculations
deg=360/((char-1)*2)
text_arc=(2*math.pi/((char-1)*2)*(i)+variable)
txs=1+radi*(math.sin(text_arc))
tys=1-radi*(math.cos(text_arc))
--print (deg)
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, ((270+(deg*(i-1)))*math.pi/180))
cairo_show_text (cr, (texttable[i]))
cairo_rotate (cr, ((-270-(deg*(i-1)))*math.pi/180))
end
end

function conky_draw_flower()
local updates=conky_parse('${updates}')
update_num=tonumber(updates)
if update_num > 5 then
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)


--FLOWER 1----------------------------------------------------------------------------
--FLOWER 1
--color
f1r=1
f1g=0
f1b=0
--size
cairo_scale (cr, 0.5, 0.5)
--position
cairo_translate (cr, 500, 250)
--draw background circle
circrad=200
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f1r, f1g, f1b, .5);
cairo_fill (cr);
--draw indicator circle
local fl1num=conky_parse('${cpu}')
fl1=tonumber(fl1num)
circrad=(fl1*1.5)+50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, 1, 0, 0, .5);
cairo_fill (cr);
--flower shape
cairo_move_to (cr, 100, 100);
cairo_curve_to (cr, 100, 150, 200, 173, 200, 173);
cairo_curve_to (cr, 230, 75, 187, 50, 187, 50);
cairo_curve_to (cr, 230, 75, 300, 0, 300, 0);
cairo_curve_to (cr, 230, -75, 187, -50, 187, -50);
cairo_curve_to (cr, 230, -75, 200, -173, 200, -173);
cairo_curve_to (cr, 100, -150, 100, -100, 100, -100);
cairo_curve_to (cr, 100, -150, 0, -173, 0, -173);
cairo_curve_to (cr, -30, -75, 13, -50, 13, -50);
cairo_curve_to (cr, -30, -75, -100, 0, -100, 0);
cairo_curve_to (cr, -30, 75, 13, 50, 13, 50);
cairo_curve_to (cr, -30, 75, 0, 173, 0, 173);
cairo_curve_to (cr, 100, 150, 100, 100, 100, 100);
cairo_close_path (cr);
--draw circle
circrad=205
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_new_sub_path (cr); cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_new_sub_path (cr); cairo_close_path(cr)
--fill
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_set_source_rgba (cr, 0, 0, 0, 1);
cairo_fill (cr);
--draw center circle
circrad=50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, 1, 1, 0, 1);
cairo_fill (cr);
--FLOWER 2----------------------------------------------------------------------------
--FLOWER 2
--color
f2r=0
f2g=1
f2b=1
--size
cairo_scale (cr, 1, 1)
--position across then up (translate is relative to last translate position)
cairo_translate (cr, 350, 200)
--draw background circle
circrad=200
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f2r, f2g, f2b, .5);
cairo_fill (cr);
--draw indicator circle
local fl2num=conky_parse('${memperc}')
fl2=tonumber(fl2num)
circrad=(fl2*1.5)+50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f2r, f2g, f2b, .5);
cairo_fill (cr);
--flower shape
cairo_move_to (cr, 100, 100);
cairo_curve_to (cr, 100, 150, 200, 173, 200, 173);
cairo_curve_to (cr, 230, 75, 187, 50, 187, 50);
cairo_curve_to (cr, 230, 75, 300, 0, 300, 0);
cairo_curve_to (cr, 230, -75, 187, -50, 187, -50);
cairo_curve_to (cr, 230, -75, 200, -173, 200, -173);
cairo_curve_to (cr, 100, -150, 100, -100, 100, -100);
cairo_curve_to (cr, 100, -150, 0, -173, 0, -173);
cairo_curve_to (cr, -30, -75, 13, -50, 13, -50);
cairo_curve_to (cr, -30, -75, -100, 0, -100, 0);
cairo_curve_to (cr, -30, 75, 13, 50, 13, 50);
cairo_curve_to (cr, -30, 75, 0, 173, 0, 173);
cairo_curve_to (cr, 100, 150, 100, 100, 100, 100);
cairo_close_path (cr);
--draw circle
circrad=205
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_new_sub_path (cr); cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_new_sub_path (cr); cairo_close_path(cr)
--fill
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_set_source_rgba (cr, 0, 0, 0, 1);
cairo_fill (cr);
--draw center circle
circrad=50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, 1, 1, 0, 1);
cairo_fill (cr);
--FLOWER 3----------------------------------------------------------------------------
--FLOWER 3
--color
f3r=0.6
f3g=0.0
f3b=1
--size
cairo_scale (cr, 1, 1)
--position across then up (translate is relative to last translate position)
cairo_translate (cr, -700, 0)
--draw background circle
circrad=200
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f3r, f3g, f3b, .5);
cairo_fill (cr);
--draw indicator circle
local fl3num=conky_parse('${fs_used_perc /}')
fl3=tonumber(fl3num)
circrad=(fl3*1.5)+50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f3r, f3g, f3b, .5);
cairo_fill (cr);
--flower shape
cairo_move_to (cr, 100, 100);
cairo_curve_to (cr, 100, 150, 200, 173, 200, 173);
cairo_curve_to (cr, 230, 75, 187, 50, 187, 50);
cairo_curve_to (cr, 230, 75, 300, 0, 300, 0);
cairo_curve_to (cr, 230, -75, 187, -50, 187, -50);
cairo_curve_to (cr, 230, -75, 200, -173, 200, -173);
cairo_curve_to (cr, 100, -150, 100, -100, 100, -100);
cairo_curve_to (cr, 100, -150, 0, -173, 0, -173);
cairo_curve_to (cr, -30, -75, 13, -50, 13, -50);
cairo_curve_to (cr, -30, -75, -100, 0, -100, 0);
cairo_curve_to (cr, -30, 75, 13, 50, 13, 50);
cairo_curve_to (cr, -30, 75, 0, 173, 0, 173);
cairo_curve_to (cr, 100, 150, 100, 100, 100, 100);
cairo_close_path (cr);
--draw circle
circrad=205
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_new_sub_path (cr); cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_new_sub_path (cr); cairo_close_path(cr)
--fill
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_set_source_rgba (cr, 0, 0, 0, 1);
cairo_fill (cr);
--draw center circle
circrad=50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, 1, 1, 0, 1);
cairo_fill (cr);
--FLOWER 4----------------------------------------------------------------------------
--FLOWER 4
--color
f4r=1
f4g=0
f4b=1
--size
cairo_scale (cr, 1, 1)
--position across then up (translate is relative to last translate position)
cairo_translate (cr, 0, 400)
--draw background circle
circrad=200
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f4r, f4g, f4b, .5);
cairo_fill (cr);
--draw indicator circle
local fl4num=conky_parse('${swapperc}')
fl4=tonumber(fl4num)
circrad=(fl4*1.5)+50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f4r, f4g, f4b, .5);
cairo_fill (cr);
--flower shape
cairo_move_to (cr, 100, 100);
cairo_curve_to (cr, 100, 150, 200, 173, 200, 173);
cairo_curve_to (cr, 230, 75, 187, 50, 187, 50);
cairo_curve_to (cr, 230, 75, 300, 0, 300, 0);
cairo_curve_to (cr, 230, -75, 187, -50, 187, -50);
cairo_curve_to (cr, 230, -75, 200, -173, 200, -173);
cairo_curve_to (cr, 100, -150, 100, -100, 100, -100);
cairo_curve_to (cr, 100, -150, 0, -173, 0, -173);
cairo_curve_to (cr, -30, -75, 13, -50, 13, -50);
cairo_curve_to (cr, -30, -75, -100, 0, -100, 0);
cairo_curve_to (cr, -30, 75, 13, 50, 13, 50);
cairo_curve_to (cr, -30, 75, 0, 173, 0, 173);
cairo_curve_to (cr, 100, 150, 100, 100, 100, 100);
cairo_close_path (cr);
--draw circle
circrad=205
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_new_sub_path (cr); cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_new_sub_path (cr); cairo_close_path(cr)
--fill
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_set_source_rgba (cr, 0, 0, 0, 1);
cairo_fill (cr);
--draw center circle
circrad=50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
cairo_set_source_rgba (cr, 1, 1, 0, 1);
cairo_fill (cr);
--FLOWER 5----------------------------------------------------------------------------
--FLOWER 5
--color
f5r=1
f5g=1
f5b=0
--size
cairo_scale (cr, 1, 1)
--position across then up (translate is relative to last translate position)
cairo_translate (cr, 350, 200)
--draw background circle
circrad=200
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f5r, f5g, f5b, .5);
cairo_fill (cr);
--draw indicator circle
local fl5num=conky_parse('${cpu}')
fl5=tonumber(fl5num)
circrad=(fl5*1.5)+50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f5r, f5g, f5b, .5);
cairo_fill (cr);
--flower shape
cairo_move_to (cr, 100, 100);
cairo_curve_to (cr, 100, 150, 200, 173, 200, 173);
cairo_curve_to (cr, 230, 75, 187, 50, 187, 50);
cairo_curve_to (cr, 230, 75, 300, 0, 300, 0);
cairo_curve_to (cr, 230, -75, 187, -50, 187, -50);
cairo_curve_to (cr, 230, -75, 200, -173, 200, -173);
cairo_curve_to (cr, 100, -150, 100, -100, 100, -100);
cairo_curve_to (cr, 100, -150, 0, -173, 0, -173);
cairo_curve_to (cr, -30, -75, 13, -50, 13, -50);
cairo_curve_to (cr, -30, -75, -100, 0, -100, 0);
cairo_curve_to (cr, -30, 75, 13, 50, 13, 50);
cairo_curve_to (cr, -30, 75, 0, 173, 0, 173);
cairo_curve_to (cr, 100, 150, 100, 100, 100, 100);
cairo_close_path (cr);
--draw circle
circrad=205
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_new_sub_path (cr); cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_new_sub_path (cr); cairo_close_path(cr)
--fill
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_set_source_rgba (cr, 0, 0, 0, 1);
cairo_fill (cr);
--draw center circle
circrad=50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
cairo_set_source_rgba (cr, 1, 1, 0, 1);
cairo_fill (cr);
--FLOWER 6----------------------------------------------------------------------------
--FLOWER 6
--color
f6r=1
f6g=.5
f6b=0
--size
cairo_scale (cr, 1, 1)
--position across then up (translate is relative to last translate position)
cairo_translate (cr, 350, -200)
--draw background circle
circrad=200
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f6r, f6g, f6b, .5);
cairo_fill (cr);
--draw indicator circle
local fl6num=conky_parse('${cpu}')
fl6=tonumber(fl6num)
circrad=(fl5*1.5)+50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
--fill
cairo_set_source_rgba (cr, f6r, f6g, f6b, .5);
cairo_fill (cr);
--flower shape
cairo_move_to (cr, 100, 100);
cairo_curve_to (cr, 100, 150, 200, 173, 200, 173);
cairo_curve_to (cr, 230, 75, 187, 50, 187, 50);
cairo_curve_to (cr, 230, 75, 300, 0, 300, 0);
cairo_curve_to (cr, 230, -75, 187, -50, 187, -50);
cairo_curve_to (cr, 230, -75, 200, -173, 200, -173);
cairo_curve_to (cr, 100, -150, 100, -100, 100, -100);
cairo_curve_to (cr, 100, -150, 0, -173, 0, -173);
cairo_curve_to (cr, -30, -75, 13, -50, 13, -50);
cairo_curve_to (cr, -30, -75, -100, 0, -100, 0);
cairo_curve_to (cr, -30, 75, 13, 50, 13, 50);
cairo_curve_to (cr, -30, 75, 0, 173, 0, 173);
cairo_curve_to (cr, 100, 150, 100, 100, 100, 100);
cairo_close_path (cr);
--draw circle
circrad=205
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_new_sub_path (cr); cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_new_sub_path (cr); cairo_close_path(cr)
--fill
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_set_source_rgba (cr, 0, 0, 0, 1);
cairo_fill (cr);
--draw center circle
circrad=50
circx=100
circy=0
cairo_move_to (cr, 100, 100);
cairo_arc(cr,circx,circy,circrad,0,2*math.pi)
cairo_close_path(cr)
cairo_set_source_rgba (cr, 1, 1, 0, 1);
cairo_fill (cr);

-----description of variables for circlewriting function
--eg circlewriting(A, B, C, D, E, F, G, H, I, J, K, L)
--A = text to be written, place straight text in quotes.
--B = total number of characters, including spaces and punctuation
--C = font, place font in quotes
--D = font size
--E = radius of the circle
--F = horizontal position
--G = vertical position
--H = color red
--I = color green
--J = color blue
--K = a variable to get the text lined up. I havn't quite figured out how this number is generated!
--but without it the text will no line up correctly. For text along top of circle this number is -ve
--start at about half of B, increasing negative moves text counter clockwise
--circlewriting("TEXT TEXT TEXT", 14, "Mono", 18, 100, 150, 150, 1, 1, 1, 1, -8.16)

--FLOWER 1 TITLE
cairo_translate (cr, -260, -590)
test=circlewriting("PROCESSOR", 9, "White Rabbit", 30, 205, 7, -10, f1r, f1g, f1b, 0.8, -2)
--FLOWER 2 TITLE
cairo_translate (cr, 348, 200)
test=circlewriting("MEMORY", 6, "White Rabbit", 30, 205, 9, -10, f2r, f2g, f2b, 0.8, -2.24)
--FLOWER 3 TITLE
cairo_translate (cr, -698, 0)
test=circlewriting("FILESYSTEM USED", 15, "White Rabbit", 30, 205, 7, -10, f3r, f3g, f3b, 0.8, -8.12)
--FLOWER 4 TITLE
cairo_translate (cr, 0, 400)
test=circlewriting("SWAP PARTITION", 14, "White Rabbit", 30, 205, 7, -11, f4r, f4g, f4b, 0.8, -8.13)
--FLOWER 5 TITLE
cairo_translate (cr, 350, 200)
test=circlewriting("BATTERY", 7, "White Rabbit", 30, 205, 7, -10, f5r, f5g, f5b, 0.8, -8.41)
--FLOWER 6 TITLE
cairo_translate (cr, 350, -200)
test=circlewriting("CONNECTION", 10, "White Rabbit", 30, 205, 7, -10, f6r, f6g, f6b, 0.8, -8.25)
--draw center clock heart
scale=1.75
cairo_set_source_rgba (cr, 255/255, 100/255, 130/255, 1)
cairo_translate (cr, -690, -570)
cairo_move_to (cr, 200*scale, 150*scale);
cairo_curve_to (cr, 210*scale, 90*scale, 290*scale, 90*scale, 300*scale, 150*scale);
cairo_curve_to (cr, 300*scale, 150*scale, 320*scale, 250*scale, 200*scale, 300*scale);
cairo_curve_to (cr, 200*scale, 300*scale, 80*scale, 250*scale, 100*scale, 150*scale);
cairo_curve_to (cr, 110*scale, 90*scale, 190*scale, 90*scale, 200*scale, 150*scale);
cairo_close_path (cr);
cairo_fill (cr)

--clock
local clock_r=85
local xc=350
local yc=390
shadow_width=5
shadow_xoffset=0
shadow_yoffset=2
show_seconds=true
-- 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

-- 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,0,0,0,0.5)
cairo_stroke(cr)

-- Draw minute hand
xm=xc+0.9*clock_r*math.sin(mins_arc)
ym=yc-0.9*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
end
end

No comments:

Post a Comment