2013/02/08

clock

This is simple clock.
This is a graphic superposition of multiple pages.

//----------------------------------------------------------------------------------------------
// clock
//----------------------------------------------------------------------------------------------
// Main
int hour,min,sec
int hour0=-1,min0=-1,sec0=-1
int cx,cy,x,y
int wx,wy
width(0)
getWidth(wx,wy)
width(64,20)
switch deviceType()
    case 2:
    case 3:
    case 4:
        width(32,30)
endswitch
tcolor(-THWHITE,0,0,255)
cx=wx/2
cy=wy/2
//
vpriority(TPAGE,GPAGE2,GPAGE1,GPAGE0,GPAGE3)
vpage(B_TPAGE or B_GPAGE0 or B_GPAGE1 or B_GPAGE2 or B_GPAGE3,YES)
int gx=300,gy=400
int r=gx/2
//
setExitKey()
while (inkey()<>'!')
    getTime()
    if hour0<>hour then {
        // hour
        setBackGround(hour)
//        apage(GPAGE0):wipe()
//        gborder(3,-TGREEN,0,0,255)
//        lineWidth(6)
//        gcolor(-THRED,0,0,235)
//        calc_endPoint(r*2/3,hour,12)
//        line(cx,cy,x,y)
        hour0=hour
    }
    if min0<>min then {
        // min
        apage(GPAGE1):wipe()
        lineWidth(4)
        gcolor(-THMAGENTA,0,0,255)
        calc_endPoint(r,min,60)
        line(cx,cy,x,y)
        min0=min
        //
        // hour
        apage(GPAGE0):wipe()
        gborder(3,-TGREEN,0,0,255)
        lineWidth(6)
        gcolor(-THRED,0,0,235)
        calc_endPoint(r*2/3,hour*(60/12)+(min/12),60)
        line(cx,cy,x,y)
    }
    if sec0<>sec then {
        locate(1,1):print using "%%:%%:%%",hour,min,sec
        // sec
        apage(GPAGE2):wipe()
        lineWidth(2)
        gcolor(-THYELLOW,0,0,255)
        calc_endPoint(r,sec,60)
        line(cx,cy,x,y)
        sec0=sec
    }
endwhile
end
//----------------------------------------------------------------------------------------------
// 関数 / Functions
//----------------------------------------------------------------------------------------------
func calc_endPoint(r;int,t;int,interval;int)
// r:radius t:time interval:Interval scale
    float cof = pi(2) / interval
    x = int( r * sin(cof * t)) + cx
    y = int(-r * cos(cof * t)) + cy
endfunc
func getTime()
    str tm$=time$
    hour=val(left$(tm$,2))
    min =val(mid$(tm$,4,2))
    sec =val(right$(tm$,2))
endfunc
func setBackGround(hour;int)
    str backGroundFname
    backGroundFname="girl4.jpg"
    if hour>= 0 and hour< 6 then backGroundFname="girl1.png"
    if hour>= 6 and hour<12 then backGroundFname="girl2.jpg"
    if hour>=12 and hour<18 then backGroundFname="girl3.png"
    apage(GPAGE3)
    wipe()
    imgLoad((wx-gx)/2,(wy-gy)/2,gx,gy,backGroundFname)
    //
    gcolor(-TCYAN,0,0,200)
    //circle(cx,cy,10,0,pi(2),NO,YES)
    circle(cx,cy,10,,,NO,YES):// V1.6
    blend(BlendModeXOR)
    //circle(cx,cy, 5,0,pi(2),NO,YES)
    circle(cx,cy, 5,,,NO,YES):// v1.6
    blend(BlendModeNormal)
endfunc
//----------------------------------------------------------------------------------------------
func setExitKey()
    str exit$
    if isLocalizeJapan() then {
        exit$="中断"
    } else {
        exit$="exit"
    }
    setFunctionKey(0,exit$,'!')
    displayFunctionKey(YES,0,0)
    kBackgroundAlpha(0.7)
endfunc
//--------------------------------------------------------------------------------------------


Zip File : XBclock.zip (It is include imagefile. So Need to be imported.)


Zip archive file : XBetc.zip

No comments:

Post a Comment