chuankay 发表于 2013-6-9 17:20:28

Allegro 界面的时钟

本帖最后由 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

vivienluo 发表于 2013-6-9 19:09:34

这个很不错,很有创意。。。。楼主强人啊。。。。{:soso__8968018481728829654_1:}

hayden 发表于 2013-6-9 21:38:12

顶一个!!

chuankay 发表于 2013-6-9 22:52:20

子木 发表于 2013-6-9 21:45 static/image/common/back.gif
咋加载成功后没画面啊

不好意思刚开始清零有问题:boundp('timerIDS) || boundp('timerIDM) || boundp('timerIDH)
有一处s应该是大写,写成小写了。快下班了比较激动优化完没有测试一下,实在抱歉。

PCB设计专家 发表于 2013-6-12 10:29:42

;P;P;P;P;P;P;P

chuankay 发表于 2013-6-14 22:12:07

子木 发表于 2013-6-14 21:46 static/image/common/back.gif
我把那处小写的换成大写后还是没画面,出现如下提示

HI 子木:显示的文字应该是在编译器里面显示的吧,第一函数就是 clock() 就是主函数,在编译器中运行clock()就可以了啊(要一个空白的brd哦,我参考的函数是16.5的),建议重新复制代码试试看,函数都比较简单,看看提提错!

chuankay 发表于 2013-6-15 21:07:22

子木 发表于 2013-6-15 20:52 static/image/common/back.gif
哦,是有前提条件嗖

是的呀 随便写写的 只为简单实现功能 没考虑太多 所以导致功能实现局限性

chuankay 发表于 2013-6-16 11:11:48

子木 发表于 2013-6-16 10:51 static/image/common/back.gif
不过很有创意

之前发一个帖子关于form中加动态logo的,只是提了下,所以这个贴也是为了补充如何加动态logo的主题,有兴趣可以试试加一个动态logo啊。

chuankay 发表于 2013-6-17 23:27:06

子木 发表于 2013-6-17 22:57 static/image/common/back.gif
如果在16.3上面显示,需要怎么修改代码呢?

函数比较简单,虽然是参考16.5的函数,但是在16.3上应该适用,我记得截图就是16.3版本的。

chuankay 发表于 2013-6-18 20:47:20

子木 发表于 2013-6-18 18:55 static/image/common/back.gif
是吗,为啥我这里加载成功后还是没画面啊?

HI 子木:
       刚试了一下,时钟的是在原点生成的,如果原点比较偏也是不行的,下图是刚刚生成的钟表图,对照函数看看吧,里面还有些地方写的不合理,看了多指正。


页: [1] 2 3 4
查看完整版本: Allegro 界面的时钟