|
本帖最后由 chuankay 于 2013-6-9 23:17 编辑
今天要放假了 ,比较激动,本想写个倒计时的代码的,觉得被领导发现不好,写个时钟,还能复习函数。(注:之前发的代码有误,优化后没有及时测试,代码可能不是最简洁的,大家有意见,多提,共同进步。)
时钟效果
- ; load("clock.il")
- ; by chen_ck
- ; allegro-skill论坛学习交流用
- axlCmdRegister("clock" ,'clock)
- axlCmdRegister("stop" , 'stop)
- defun( clock ()
- gc()
- S = nil
- M = nil
- H = nil
- if(boundp('timerIDS) || boundp('timerIDM) || boundp('timerIDH)
- then
- stop()
- );if
- initializer_time()
- axlClearSelSet()
- axlSetFindFilter(?enabled list("noall" "lines") ?onButtons list("noall" "lines"))
- lines = axlGetSelSet(axlAddSelectAll())
- foreach(db lines
- cond(
- (db->layer == "BOARD GEOMETRY/OUTLINE" S = db)
- (db->layer == "ETCH/TOP" M = db)
- (db->layer == "ETCH/BOTTOM" H = db)
- );cond
- );foreach
- timerIDS = nil
- timerIDM = nil
- timerIDH = nil
- timerIDS = axlUIWTimerAdd(nil 1000 nil 'updateS)
- timerIDM = axlUIWTimerAdd(nil 60000 nil 'updateM)
- timerIDH = axlUIWTimerAdd(nil 3600000 nil 'updateH)
- );defun
-
- defun(updateS (window timerIDS elapseTime)
- axlTransformObject(S, ?angle -6 ?origin 0:0)
- );defun
- defun(updateM (window timerIDM elapseTime)
- axlTransformObject(M, ?angle -6 ?origin 0:0)
- );defun
- defun(updateH (window timerIDH elapseTime)
- axlTransformObject(H, ?angle -6 ?origin 0:0)
- );defun
-
- defun( initializer_time ()
- time = nth(2 parseString(getCurrentTime()))
- timeH = atoi(car(parseString(time ":")))
- timeM = atoi(cadr(parseString(time ":")))
- timeS = atoi(caddr(parseString(time ":")))
- S = caar(axlDBCreateLine( (list 0:0 0:400), 10, "BOARD GEOMETRY/OUTLINE"))
- M = caar(axlDBCreateLine( (list 0:0 0:360), 20, "ETCH/TOP"))
- H = caar(axlDBCreateLine( (list 0:0 0:300), 40, "ETCH/BOTTOM"))
- axlDBCreateCircle( list(0:0 500) , 5 , "PACKAGE GEOMETRY/PLACE_BOUND_TOP")
- axlDBCreateCircle( list(0:0 450) , 5 , "PACKAGE GEOMETRY/PLACE_BOUND_TOP")
- BAR = caar(axlDBCreateLine( (list 0:360 0:420), 25, "PACKAGE GEOMETRY/PLACE_BOUND_TOP"))
- for(i 1 11
- angle_ = i * 30
- axlCopyObject(BAR , ?angle eval(angle_) ?origin 0:0)
- );for
- myorient = make_axlTextOrientation(?textBlock "7", ?rotation 0.0,?mirrored nil, ?justify "center")
- axlDBCreateText("CHEN_CK", 0:165, myorient,"PACKAGE GEOMETRY/PLACE_BOUND_TOP", nil)
-
- axlTransformObject(S, ?angle -timeS * 6 ?origin 0:0)
- axlTransformObject(M, ?angle -timeM * 6 ?origin 0:0)
- axlTransformObject(H, ?angle (-timeH + 12 - timeM / 60.0) * 30 , ?origin 0:0)
- );defun
-
- defun( stop ()
- axlUIWTimerRemove(timerIDS)
- axlUIWTimerRemove(timerIDM)
- axlUIWTimerRemove(timerIDH)
- );defun stop
复制代码 |
评分
-
查看全部评分
|