源地址:http://tieba.baidu.com/f?kz=673179640,效果不是很好,但还能看,请谅解!
代码如下:
- @echo off
- setlocal enabledelayedexpansion
- color 9f
- title 批处理时钟 by liuzhaonan11
- call:main
- pause
- exit /b
- :main
- set /a "height=40, width=40, lines=height/2+1, cols=width+1"
- mode con lines=!lines! cols=!cols!
- set /a "centerx=height/2+1, centery=width/2-1"
- set /a "lengthh=12,lengthm=16,lengths=18,radius=18"
- call:math
- :loop
- setlocal
- 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=timeh%%12"
- set /a "angleh=30*timeh+timem/12*6, anglem=6*timem, angles=6*times"
- call:cleartable table !height! !width!
- for %%i in (h,m,s) do (
- call:cleartable table%%i !height! !width!
- set /a "x%%i=centerx+sin!angle%%i!, y%%i=centery+cos!angle%%i!"
- call:drawline table%%i !centerx! !centery! !x%%i! !y%%i!
- call:add table%%i !length%%i! table
- )
- for /l %%i in (0,30,360) do (
- set /a "x=centerx+(sin%%i*radius)/100, y=centery+(cos%%i*radius)/100"
- set "table_!x!_!y!=1"
- )
- call:table2graph table graph
- set /a "gctc=centerx, gctl=graph.h-(centery-1)/2" & set "graph_!gctl!_!gctc!="
- call:graph2string graph string
- cls
- call:print string
- (echo !date! !time:~0,-3!)
- endlocal
- goto loop
- exit /b
-
- :math
- set /a "sin0=0, sin6=11, sin12=21, sin18=31, sin24=41, sin30=50, sin36=59, sin42=67, sin48=74, sin54=81, sin60=87, sin66=91, sin72=95, sin78=98, sin84=99, sin90=100"
- 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=%%i-90+360, a4=a4%%360"
- set /a "cos!a4!=!sin%%i!"
- )
- exit /b
- :add
- REM add table1 length table2
- for /l %%y in (1,1,!%~1.h!) do for /l %%x in (1,1,!%~1.w!) do (
- if "!%~1_%%x_%%y!"=="1" (
- set /a "i=%~2*%~2-(%%x-!centerx!)*(%%x-!centerx!)-(%%y-!centery!)*(%%y-!centery!)"
- if !i! geq 0 (
- set "%~3_%%x_%%y=1"
- )
- )
- )
- exit /b
- :cleartable
- REM cleartable table height width
- set /a "%~1.h=%~2, %~1.w=%~3"
- ::- for /l %%y in (1,1,!%~1.h!) do for /l %%x in (1,1,!%~1.w!) do set "%~1_%%x_%%y="
- exit /b
- :print
- for /l %%l in (1,1,!%~1.n!) do (echo:!%~1_%%l!)
- exit /b
- :graph2string
- set /a "%~2.n=%~1.h"
- for /l %%l in (1,1,!%~1.h!) do (
- set "%~2_%%l="
- for /l %%c in (1,1,!%~1.w!) do (
- if "!%~1_%%l_%%c!"=="" ( set "%~2_%%l=!%~2_%%l! "
- ) else set "%~2_%%l=!%~2_%%l!!%~1_%%l_%%c!"
- )
- )
- exit /b
- :table2graph
- set /a "%~2.w=%~1.w, %~2.h=%~1.h/2"
- for /l %%l in (1,1,!%~2.h!) do ( REM 每一行
- set /a "y1=2*(!%~2.h!-%%l)+2, y2=2*(!%~2.h!-%%l)+1"
- for /f "delims=" %%i in ("!y1!") do for /f "delims=" %%j in ("!y2!") do (
- for /l %%c in (1,1,!%~2.w!) do ( REM 每一列
- if not "!%~1_%%c_%%i!"=="1" (
- if not "!%~1_%%c_%%j!"=="1" (
- set "%~2_%%l_%%c="
- ) else (
- set "%~2_%%l_%%c=."
- )
- ) else (
- if not "!%~1_%%c_%%j!"=="1" (
- set "%~2_%%l_%%c='"
- ) else (
- set "%~2_%%l_%%c=:"
- )
- )
- )
- )
- )
- exit /b
- :drawline
- REM drawline table x1 y1 x2 y2
- set /a "x1=%~2, y1=%~3, x2=%~4, y2=!%~5"
- set /a "rx=x1-x2" & set /a "rx=!rx:-=!"
- set /a "ry=y1-y2" & set /a "ry=!ry:-=!"
- if !rx! geq !ry! ( REM 比较平
- if !x1! lss !x2! for /l %%i in (!x1!,1,!x2!) do ( REM 点1在左边
- set /a "ideal=(%y1%*(%x2%-%%i)+%y2%*(%%i-%x1%))/(%x2%-%x1%)"
- set "%~1_%%i_!ideal!=1"
- ) else if !x2! lss !x1! for /l %%i in (!x2!,1,!x1!) do ( REM 点2在左边
- set /a "ideal=(%y2%*(%x1%-%%i)+%y1%*(%%i-%x2%))/(%x1%-%x2%)"
- set "%~1_%%i_!ideal!=1"
- ) else ( REM 一个点
- set "%~1_!x1!_!y1!=1"
- )
- ) else ( REM 比较斜
- if !y1! lss !y2! for /l %%i in (!y1!,1,!y2!) do ( REM 点1在下边
- set /a "ideal=(%x1%*(%y2%-%%i)+%x2%*(%%i-%y1%))/(%y2%-%y1%)"
- set "%~1_!ideal!_%%i=1"
- ) else if !y2! lss !y1! for /l %%i in (!y2!,1,!y1!) do ( REM 点2在下边
- set /a "ideal=(%x2%*(%y1%-%%i)+%x1%*(%%i-%y2%))/(%y1%-%y2%)"
- set "%~1_!ideal!_%%i=1"
- ) else ( REM 一个点
- set "%~1_!x1!_!y1!=1"
- )
- )
- exit /b
复制代码
|