我来提提速,把图形初始化放在循环外,利用setlocal enabledelayedexpansion和endlocal来恢复变量
分和秒防前导0错误可以这样避免:set/a sec=1!time:~6,2!-100
另外有些地方还可以提速,
1。分针和时针,也可以像秒针一样采用触发绘出
2。以“行”为单位存放图形数据,利用串截取再重组方式来更新显示点,这样可以避免刷屏时对每个点都要用set 来重组一次,并且可以减少变量占用空间和变量的数量
这样改进后,每秒刷5次屏应该都可以。我没有时间搞了,看楼主的吧。
- @echo off
- msg %username% /time:60 请右键单击时钟窗口标题栏, 选择“属性”-^>“字体”选项卡,“点阵字体”,大小: 6 x 12,以得到更好的显示效果
- title 指针时钟 2.0 by neorobin 叶结点
- setlocal enabledelayedexpansion
- color 9f
- set /a "size=19, HandS=size-1, HandM=HandS-4, HandH=HandM-4, rScale=size-1"
- set /a "xStart=size, xEnd=-size, yStart=-size, yEnd=size"
- set /a "Cols=(size*2+1)*2, Lines=size*2+1+1"
- (set PntCenter=◎)&(set PntH=●)&(set PntM=○)&(set PntS=·)&(set PntB=▓)
- (set RomanNumbers=ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ)
- set /a "leftSpaces=(size*2+1-13)/2-2" & (set Blanks=)
- for /l %%i in (1,1,!leftSpaces!) do (set Blanks=!PntB!!Blanks!)
- mode con cols=!Cols! Lines=!Lines!
- call :math
- if %time:~6,2% geq 10 (set sec=%time:~6,2%) else (set sec=%time:~7,1%)
-
- (call :clrScr scr !PntB!)
- rem 标12个刻度
- for /l %%z in (0,1,11) do (
- (set /a angle=%%z+1) && (set /a angle*=30)
- set /a "x=cos!angle!*rScale/factor, y=sin!angle!*rScale/factor"
- set "scr_!x!_!y!=!RomanNumbers:~%%z,1!"
- )
-
- :loop
- (set sec1=!sec!)
- setlocal enabledelayedexpansion
- for %%i in (h,m,s) do (call :drawHand !Hand%%i! %%i)
- set "scr_0_0=!PntCenter!"
- (set strScr=)
- for /l %%x in (!xStart!,-1,!xEnd!) do for /l %%y in (!yStart!,1,!yEnd!) do (
- (set strScr=!strScr!!scr_%%x_%%y!)
- )
- cls&(set /p=!strScr! !Blanks! !date! !time:~0,-3! !Blanks!<NUL)
- endlocal
-
- :testSec
- ::if %time:~6,2% geq 10 (set sec=%time:~6,2%) else (set sec=%time:~7,1%)
- set/a sec=1!time:~6,2!-100&if !sec! neq !sec1! (goto loop) else goto testSec
- exit /b
-
- rem ========== end of main program =================================================================
-
- :math
- set /a "sin0=0,sin6=105,sin12=208,sin18=309,sin24=407,sin30=500,sin36=588,sin42=669,sin48=743,sin54=809,sin60=866,sin66=914,sin72=951,sin78=978,sin84=995,sin90=1000"
- (set /a factor=1000)
- for /l %%i in (0, 6, 90) do (
- set /a "a1=180-%%i, a2=180+%%i, a3=360-%%i"
- set /a "sin!a1!=!sin%%i!, sin!a2!=-!sin%%i!, sin!a3!=-!sin%%i!"
- )
- for /l %%i in (0, 6, 360) do (
- set /a "a4=450-%%i, a4%%=360"
- set /a "cos%%i=sin!a4!"
- )
- exit /b
-
-
- rem drawHand !HandLength! !HandFlag!
- :drawHand
- (set timeh=!time:~0,2!)&(set timem=!time:~3,2!)&(set times=!time:~6,2!)
- for %%i in (h,m,s) do if !time%%i! lss 10 (set time%%i=!time%%i:~-1!)
- set /a "timeh%%=12"
- set /a "angleh=30*timeh+(timem+6)/12*6, anglem=6*timem, angles=6*times"
- set /a "xE=%1*cos!angle%2!*2/factor, yE=%1*sin!angle%2!*2/factor"
- call :line scr 0 0 !xE! !yE! %1 !Pnt%2!
- exit /b
-
-
- rem clrScr scr !strBlank!
- :clrScr
- for /l %%x in (!xStart!,-1,!xEnd!) do for /l %%y in (!yStart!,1,!yEnd!) do (
- (set /a inDial=size*size-%%x*%%x-%%y*%%y+1*size)&& if !inDial! geq 0 (set scr_%%x_%%y=!PntB!) else (set scr_%%x_%%y= )
- )
- exit /b
-
-
- rem line scr x1 y1 x2 y2 !LenHand! !PointChr!
- :line
- (set x0=%2)&(set y0=%3)&(set x1=%4)&(set y1=%5)&(set /a SQLenHand=%6*%6)
- set /a "steep=(y1 - y0)*(y1 - y0) - (x1 - x0)*(x1 - x0)"
- if !steep! gtr 0 (
- (set tt=!x0!&& set x0=!y0!&& set y0=!tt!)
- (set tt=!x1!&& set x1=!y1!&& set y1=!tt!)
- )
- if !x0! gtr !x1! (
- (set tt=!x0!&& set x0=!x1!&& set x1=!tt!)
- (set tt=!y0!&& set y0=!y1!&& set y1=!tt!)
- )
- set /a "deltax=x1-x0, twoDeltax=2*deltax"
- set /a "twoDeltay=2*(y1-y0)" && (set twoDeltay=!twoDeltay:-=!)
- set /a "eps=0, y=y0"
- if !y0! lss !y1! (set yStep=1) else (set yStep=-1)
- for /l %%x in (!x0!,1,!x1!) do (
- set /a "SQSum=%%x*%%x+y*y"
- if !SQSum! leq !SQLenHand! (
- if !steep! gtr 0 (set "%~1_!y!_%%x=%7") else (set "%~1_%%x_!y!=%7")
- )
- (set /a eps+=twoDeltay)
- if !eps! gtr !deltax! (set /a "y+=yStep, eps-=twoDeltax")
- )
- exit /b
复制代码
|