批处理之家's Archiver

michael8111 发表于 2010-6-14 16:28

批处理指针时钟

源地址:[url=http://tieba.baidu.com/f?kz=673179640]http://tieba.baidu.com/f?kz=673179640[/url],效果不是很好,但还能看,请谅解!

代码如下:

[code]
@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[/code]

michael8111 发表于 2010-6-14 16:42

求助:如何把这段代码中指针变直?这里的指针总是弯的

523066680 发表于 2010-6-14 18:06

我记得指针时钟有人发过呀!#@¥@#¥……

523066680 发表于 2010-6-14 18:10

回复 2楼 的帖子

哈哈 其实这个已经不弯了。两点之间构成一直线,而这个点太粗啦~

像这个:
000
      000
             000

上次qzwqzw弄了个改注册表之类的可以控制 字符大小,那个顶~

neorobin 发表于 2010-6-15 19:36

回复 2楼 的帖子

如 4 楼所述, 基于显示硬件的光栅式显示原理, 除了水平方向和垂直方向的直线外, 在显示硬件上是没有绝对的直线的, 非水平和垂直方向的直线只能用水平线段和垂直线段的组合构成折线来近似显现, 目前我所知 直线最好的画法 是 Bresenham 算法, 请参考
[url]http://cg.sjtu.edu.cn/lecture_site/chap2/mainframe212.htm[/url]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.