Wednesday, February 17, 2010

I have improved my circlewriting function significantly! No more annoying fiddling about to get it right, the function puts everything in the right place first time. I have kept the option to fine tune through variables to take into account the variations in fonts. I find this function works best with a monospace font anyway.

There are 2 function:
"circlewriting" writes text across the top of a circle, on the outside.
"circlewritingdown" writes text along the bottom of a circle on the inside.
Like so:

You can get the code for these functions here on the crunchbanglinux forum.

Several of my previous Lua scripts have used predecessors of this function. For those, just delete the old function, put in the new functions and make sure that when you activate the function you are giving it all the right information. In the code in the link above I have made the way that you feed the function data a little easier:

--text must be in quotes
text=" Circle Writing "
--font name must be in quotes
font="White Rabbit"
circlewritingdown(cr, text, font, fontsize, radius, positionx, positiony, colorred, colorgreen, colorblue, coloralpha, letterposition, letterrotation)

Information is entered line by line with well described strings.

You can also use this kind of display for "live" information. Here I am using the addzero100 function so that the numbers are always 3 digits, although because now the "text" string length is read automatically, the display will alter itself with altering length of "text".

Here is the text strings that achieved the above:

text=(" CPU " .. (addzero100(cpu)) .. "% ")

text=(" MEMORY " .. (addzero100(mem)) .. "% ")

and for reminder here is the addzero100 function:

function addzero100(num)
if tonumber(num) < 10 then
return "00" .. num
elseif tonumber(num) <100 then
return "0" .. num
else return num

I have now included the ability to set a start and finish position for the displayed text so that you can achieve results like this:

I have updated my post on the crunchbanglinux forum here. The code there outputs the above image. There is also a brief discussion regarding overcoming the alignment problems that are inherent in this function.

No comments:

Post a Comment