tiny analog clock
Wouter
wouter.abraham at pi.be
Tue Aug 17 12:30:23 EDT 2004
For those who like to fiddle with tiny analog clocks put this in a
button:
on mouseUp
if there is no grp "Clock" then goCreateOne
if the optionkey is down then
set the runclock of grp "clock" to false
exit to top
end if
setBackFace
end mouseUp
on setBackFace
if there is no grp "Clock" then goCreateOne
if the cHMS of grp "clock" is 10,14,15 then
### radius of backface
put 10 into tR
### length of hours, minutes and seconds hand
set the cHMS of grp "clock" to 7,9,10
else
put 15 into tR
set the cHMS of grp "clock" to 10,14,15
end if
put 0,0 & cr & 0,1 & cr & 1,1 & cr & 1,0 & cr & 0,0 into tA
put 0,0 & cr & 0,1 & cr & -1,1 & cr & -1,0 & cr & 0,0 into tAA
if the points of grc "backface" = "" then
put the right of me + 30 into x
put item 2 of the loc of me into y
else
put item 1 of the loc of grp "clock" into x
put item 2 of the loc of grp "clock" into y
end if
put (2 * pi / 12) into sRad
repeat with i = 1 to 12
put trunc(tR * cos (sRad * i)) + x into a
put trunc(tR * sin (sRad * i)) + y into b
if i = 12 or i = 9 then
repeat for each line j in tAA
put item 1 of j + a,item 2 of j + b & cr after aTemp
end repeat
put cr after aTemp
else if i mod 3 = 0 then
repeat for each line j in tA
put item 1 of j + a,item 2 of j + b & cr after aTemp
end repeat
put cr after aTemp
else put a,b & cr & a,b & cr & cr after aTemp
end repeat
set the points of grc "backFace" to aTemp
set the points of grc "secondsHand" to ""
set the rect of grc "secondsHand" to the rect of of grc "backFace"
set the points of grc "shadowHands" to ""
set the rect of grc "shadowHands" to the rect of of grc "backFace"
set the points of grc "timeGraph" to ""
set the rect of grc "timeGraph" to the rect of of grc "backFace"
set the runclock of grp "clock" to true
send "SetHands 0" to grp "clock"
end setBackFace
on goCreateOne
set the style of the templategraphic to polygon
set the opaque of the templategraphic to false ### to make <open>
polygons
set the linesize of the templategraphic to 1
create grc "backFace"
put the name of grc "backFace" && "and " after tList
set the colors of grc "backFace" to 88,88,88
set the linesize of the templategraphic to 2
create grc "shadowHands"
put the name of grc "shadowHands" && "and " after tList
set the colors of grc "shadowHands" to 170,170,170
set the linesize of the templategraphic to 1
create grc "timeGraph"
put the name of grc "timeGraph" && "and " after tList
set the colors of grc "timeGraph" to 50,50,50
set the linesize of the templategraphic to 1
create grc "secondsHand"
set the colors of grc "secondsHand" to red
put the name of grc "secondsHand" after tList
do "group" && tList
set the name of last grp to "Clock"
get the script of me
set the script of grp "clock" to line lineoffset("on SetHands", it)
to -1 of it
choose browse tool
end goCreateOne
on SetHands timeOffset
put (2 * pi / 60) into sRad
convert the seconds + timeOffset to dateItems
put (item 4 of it * 5) + (item 5 of it/12) - 15,\
item 5 of it - 15,item 6 of it - 15,\
item 6 of it + 15 into tTime
repeat with j = 1 to 3
put the loc of me & cr & \
round(item j of the cHMS of me * cos (sRad * item j of tTime))
+ \
item 1 of the loc of me, \
round(item j of the cHMS of me * sin (sRad * item j of tTime))
+ \
item 2 of the loc of me & cr after thepoints
end repeat
set the points of grc "secondsHand" to line 5 to 6 of thePoints
set the points of grc "shadowHands" to line 1 to 4 of thePoints
set the points of grc "timegraph" to line 1 to 4 of thePoints
if the runclock of me then send "setHands" && timeOffset to me in 1
sec
end SetHands
Beware of the mail line wraps.
Enjoy,
WA
More information about the use-livecode
mailing list