It has been done before, but this guide will help you create a clock using an image strip.
The idea here is to only have ten numbers in the strip, so that one might change the font
easily. This isn't something that may come up often, but it's useful to know if you want
to make a multicolored font for a clock.
Let's suppose we have a 6px wide image strip of numbers, 0-9 from top to bottom:
%xl(N,numbers.bmp,0,0,10)
We can use these numbers to fill in each digit for the clock. The trickiest part about this
procedure is positioning the clock. This clock will be 31 px wide, each digit being 6px, and
a colon in the center that is 3px wide. Placement for this tutorial will be in the upper left
corner (0,0), but you can move the clock by adding to the X and Y of each viewport.
We will start with the hours. I am using a 12 hour clock. The same principles apply with
a 24 hour clock, although a 12 hour clock begins at 1, while a 24 hour clock begins at 0.
Remember that subimage "a" is the number zero, and "b" is one. The first nine will be
nothing, and the last three will be a one.
#HOURS - Tens place
%V(0,0,6,-,-)
%?cl<|||||||||%xd(Nb)|%xd(Nb)|%xd(Nb)>
The ones place is a bit more complex:
#HOURS - Ones place
%V(6,0,6,-,-)
%?cl<%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Nj)|%xd(Na)|%xd(Nb)|%xd(Nc)>
This conditional has twelve values, one for each of the twelve hours. The important thing
to remember with a 12 hour clock is that it begins counting at 1, not 0. Thus, the first
entry is subimage "b", for 1. Subimages "a", "b", and "c" round out the last three values
for 10, 11, and 12.
Let's add in a blinking colon to divide hours from minutes. First, preload the image:
%xl(c,colon.bmp,0,0)
Now let's give it a viewport:
%V(12,0,3,-,-)
I'm going to use a %t tag to make it blink in half second intervals.
%t(0.5)%xd(c);%t(0.5);
The tens place for minutes is basically the same as the tens place for the hours, but
continued. Because there are sixty values for minutes and the tens digit changes
every ten values, we must make 6 sets of 10 values. The numbers 0-5 will be used,
which translates to subimages "a"-"f".
#MINUTES - Tens place
%V(15,0,6,-,-)
%?cM<%xd(Na)|%xd(Na)|%xd(Na)|%xd(Na)|%xd(Na)|%xd(Na)|%xd(Na)|%xd(Na)|%xd(Na)|%xd(Nb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xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Na)|%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Na)|%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Na)|%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Na)|%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Nj)>
Hope you found this useful! I am planning on adding it to a theme I made in order
to avoid having to make a custom .fnt, although it will have to happen eventually...
Post Merge: January 12, 2011, 01:14:52 PM
If you want the files i used to play with:
http://dl.dropbox.com/u/2255413/clock.zip