返回列表 发帖

指针式时钟

我想发这份代码, 可这里居然还要我有少尉等级, 要过500分, 我懒得等积分啊, 就这里发了.

目前尚未找到更高效的指针绘图方法, 时钟的指针绘图刷新所需 10 秒左右(几秒到十几秒), 秒针的显示已失去意义, 故只显示时针和分针, 字体请使用 CMD 默认的 8X16 字体, 至少请使用和这个宽高比相同的字体, 以得到最理想的显示效果
:: 指针时钟 作者: neorobin   neorobin@163.com   http://hi.baidu.com/leafnode
:: 指针绘图核心算法: Bresenham 直线算法
@echo off
title 批处理时钟 by neorobin
setlocal enabledelayedexpansion
color 9f
rem 6°间隔坐标表: 行偏移*字体宽*1000, 列偏移*字体高*10. 此变化可保证指针等长显示, 表盘呈圆形而非椭圆.
set table=-80,0,-80,17,-78,33,-76,49,-73,65,-69,80,-65,94,-59,107,-54,119,-47,129,-40,139,-33,146,-25,152,-17,157,-8,159,0,160,8,159,17,157,25,152,33,146,40,139,47,129,54,119,59,107,65,94,69,80,73,65,76,49,78,33,80,17,80,0,80,-17,78,-33,76,-49,73,-65,69,-80,65,-94,59,-107,54,-119,47,-129,40,-139,33,-146,25,-152,17,-157,8,-159,0,-160,-8,-159,-17,-157,-25,-152,-33,-146,-40,-139,-47,-129,-54,-119,-59,-107,-65,-94,-69,-80,-73,-65,-76,-49,-78,-33,-80,-17,
set tableLen=444
set Dial=20,69,196,398,596,709,740,691,564,362,164,51,
set DialLen=45
set PointChr=.
set Width=40
set Height=20
set Height1=21
set minPinLen=8
set hourPinLen=5
mode con cols=!Width! Lines=!Height1!
set /a scrMax=Width*Height
set /a FontHWR=16/8
set /a SQFontHWR=FontHWR*FontHWR
set /a ColO=Width/2
set /a LinO=Height/2
set /a centre=(LinO-1)*Width+ColO
set centreChr=o
:nextMin
if %time:~0,2% geq 10 (set hour=%time:~0,2%) else set hour=%time:~1,1%
if %time:~3,2% geq 10 (set min=%time:~3,2%) else set min=%time:~4,1%
if %time:~6,2% geq 10 (set sec=%time:~6,2%) else set sec=%time:~7,1%
set min1=!min!
set sec1=!sec!
set scrPointList=!Dial!
set /a scrPointListLen=DialLen
set /a PinLen=minPinLen
set /a SQPinLen=PinLen*PinLen
call :searchDIR LinOffs ColOffs !tableLen! !min!
call :line 0 0 !LinOffs! !ColOffs! scrPointList scrPointListLen
set hourScale=!hour!
if !hourScale! geq 12 set /a hourScale-=12
set /a hourScale=hourScale*30+min*30/60
set /a hourScale/=6
set /a PinLen=hourPinLen
set /a SQPinLen=PinLen*PinLen
call :searchDIR LinOffs ColOffs !tableLen! !hourScale!
call :line 0 0 !LinOffs! !ColOffs! scrPointList scrPointListLen
set Value=0
set List=!scrPointList!
set Length=!scrPointListLen!
cls
for /l %%i in (1,1,!scrMax!) do (
  set findPoint=0
  for /l %%z in (0,1,!Length!) do (
    set Value=!Value!!List:~%%z,1!
    if "!List:~%%z,1!"=="," (
      set Value=!Value:~0,-1!
      if !Value! equ %%i if !findPoint! equ 0 (
        if !Value! equ !centre! (set /p=!centreChr!<nul) else set /p=!PointChr!<nul
        set findPoint=1
      )
      set Value=
    )
  )
  if !findPoint! equ 0 set /p= <nul
)
set /p=       !date! %time:~0,-3%<nul
:nextSec
if %time:~3,2% geq 10 (set min=%time:~3,2%) else set min=%time:~4,1%
if %time:~6,2% geq 10 (set sec=%time:~6,2%) else set sec=%time:~7,1%
if !sec! neq !sec1! (
  set sec1=!sec!
  rem 更新秒数字显示
  set /p=%time:~6,2%<nul
)
if !min! neq !min1! (goto nextMin) else goto nextSec
goto :eof
:line
set x0=%1&&set y0=%2&&set x1=%3&&set y1=%4
set /a steep=(y1 - y0)*(y1 - y0) - (x1 - x0)*(x1 - x0)
if !steep! gtr 0 (
  set ttt=!x0!&& set x0=!y0!&& set y0=!ttt!
  set ttt=!x1!&& set x1=!y1!&& set y1=!ttt!
)
if !x0! gtr !x1! (
  set ttt=!x0!&& set x0=!x1!&& set x1=!ttt!
  set ttt=!y0!&& set y0=!y1!&& set y1=!ttt!
)
set /a deltax=x1-x0
set /a twoDeltax=2*deltax
set /a twoDeltay=2*(y1-y0)
if !twoDeltay! lss 0 set /a twoDeltay=-twoDeltay
set /a eps=0
set /a y=y0
if !y0! lss !y1! (set yStep=1) else set yStep=-1
for /l %%x in (!x0!,1,!x1!) do (
  if !steep! gtr 0 (set /a SQSum=%%x*%%x/SQFontHWR+y*y) else set /a SQSum=%%x*%%x+y*y/SQFontHWR
  if !SQSum! leq !SQPinLen! (
    if !steep! gtr 0 (
      set /a scrii=LinO+y-1
      set /a scrii=scrii*Width+ColO+%%x
    ) else (
      set /a scrii=LinO+%%x-1
      set /a scrii=scrii*Width+ColO+y
    )
    set %5=!scrii!,!%5!
    set /a %6+=1
    for /l %%z in (1,1,10) do (
      if !scrii! gtr 0 set /a %6+=1
      set /a scrii/=10
    )
  )
  set /a eps+=!twoDeltay!
  if !eps! gtr !deltax! (
    set /a y+=!yStep!
    set /a eps-=!twoDeltax!
  )
)
goto :eof
rem end of :line
:searchDIR
rem 调用语法 call :searchDIR LinOffs ColOffs %tableLen% %index%
rem index 为索引, 用分或秒或时的对应的索引值替换
set /a ii=%4*2
set /a jj=ii+1
set test=-1
set OffsValue=
for /l %%z in (0,1,%3) do (
  set OffsValue=!OffsValue!!table:~%%z,1!
  if "!table:~%%z,1!"=="," (
    set /a test+=1
    set OffsValue=!OffsValue:~0,-1!
    if !test! equ !ii! set /a %1=OffsValue
    if !test! equ !jj! set /a %2=OffsValue
    set OffsValue=
  )
)
goto :eofCOPY

TOP

返回列表