批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

批处理指针时钟

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

代码如下:

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. color 9f
  4. title 批处理时钟 by liuzhaonan11
  5. call:main
  6. pause
  7. exit /b
  8. :main
  9. set /a "height=40, width=40, lines=height/2+1, cols=width+1"
  10. mode con lines=!lines! cols=!cols!
  11. set /a "centerx=height/2+1, centery=width/2-1"
  12. set /a "lengthh=12,lengthm=16,lengths=18,radius=18"
  13. call:math
  14. :loop
  15. setlocal
  16. set "timeh=!time:~0,2!" & set "timem=!time:~3,2!" & set "times=!time:~6,2!"
  17. for %%i in (h,m,s) do if !time%%i! lss 10 set "time%%i=!time%%i:~-1!"
  18. set /a "timeh=timeh%%12"
  19. set /a "angleh=30*timeh+timem/12*6, anglem=6*timem, angles=6*times"
  20. call:cleartable table !height! !width!
  21. for %%i in (h,m,s) do (
  22. call:cleartable table%%i !height! !width!
  23. set /a "x%%i=centerx+sin!angle%%i!, y%%i=centery+cos!angle%%i!"
  24. call:drawline table%%i !centerx! !centery! !x%%i! !y%%i!
  25. call:add table%%i !length%%i! table
  26. )
  27. for /l %%i in (0,30,360) do (
  28. set /a "x=centerx+(sin%%i*radius)/100, y=centery+(cos%%i*radius)/100"
  29. set "table_!x!_!y!=1"
  30. )
  31. call:table2graph table graph
  32. set /a "gctc=centerx, gctl=graph.h-(centery-1)/2" & set "graph_!gctl!_!gctc!="
  33. call:graph2string graph string
  34. cls
  35. call:print string
  36. (echo         !date! !time:~0,-3!)
  37. endlocal
  38. goto loop
  39. exit /b
  40. :math
  41. 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"
  42. for /l %%i in (0, 6, 90) do (
  43. set /a "a1=180-%%i, a2=180+%%i, a3=360-%%i"
  44. set /a "sin!a1!=!sin%%i!, sin!a2!=-!sin%%i!, sin!a3!=-!sin%%i!"
  45. )
  46. for /l %%i in (0, 6, 360) do (
  47. set /a "a4=%%i-90+360, a4=a4%%360"
  48. set /a "cos!a4!=!sin%%i!"
  49. )
  50. exit /b
  51. :add
  52. REM add table1 length table2
  53. for /l %%y in (1,1,!%~1.h!) do for /l %%x in (1,1,!%~1.w!) do (
  54. if "!%~1_%%x_%%y!"=="1" (
  55. set /a "i=%~2*%~2-(%%x-!centerx!)*(%%x-!centerx!)-(%%y-!centery!)*(%%y-!centery!)"
  56. if !i! geq 0 (
  57. set "%~3_%%x_%%y=1"
  58. )
  59. )
  60. )
  61. exit /b
  62. :cleartable
  63. REM cleartable table height width
  64. set /a "%~1.h=%~2, %~1.w=%~3"
  65. ::- for /l %%y in (1,1,!%~1.h!) do for /l %%x in (1,1,!%~1.w!) do set "%~1_%%x_%%y="
  66. exit /b
  67. :print
  68. for /l %%l in (1,1,!%~1.n!) do (echo:!%~1_%%l!)
  69. exit /b
  70. :graph2string
  71. set /a "%~2.n=%~1.h"
  72. for /l %%l in (1,1,!%~1.h!) do (
  73. set "%~2_%%l="
  74. for /l %%c in (1,1,!%~1.w!) do (
  75. if "!%~1_%%l_%%c!"=="" ( set "%~2_%%l=!%~2_%%l! "
  76. ) else set "%~2_%%l=!%~2_%%l!!%~1_%%l_%%c!"
  77. )
  78. )
  79. exit /b
  80. :table2graph
  81. set /a "%~2.w=%~1.w, %~2.h=%~1.h/2"
  82. for /l %%l in (1,1,!%~2.h!) do ( REM 每一行
  83. set /a "y1=2*(!%~2.h!-%%l)+2, y2=2*(!%~2.h!-%%l)+1"
  84. for /f "delims=" %%i in ("!y1!") do for /f "delims=" %%j in ("!y2!") do (
  85. for /l %%c in (1,1,!%~2.w!) do ( REM 每一列
  86. if not "!%~1_%%c_%%i!"=="1" (
  87. if not "!%~1_%%c_%%j!"=="1" (
  88. set "%~2_%%l_%%c="
  89. ) else (
  90. set "%~2_%%l_%%c=."
  91. )
  92. ) else (
  93. if not "!%~1_%%c_%%j!"=="1" (
  94. set "%~2_%%l_%%c='"
  95. ) else (
  96. set "%~2_%%l_%%c=:"
  97. )
  98. )
  99. )
  100. )
  101. )
  102. exit /b
  103. :drawline
  104. REM drawline table x1 y1 x2 y2
  105. set /a "x1=%~2, y1=%~3, x2=%~4, y2=!%~5"
  106. set /a "rx=x1-x2" & set /a "rx=!rx:-=!"
  107. set /a "ry=y1-y2" & set /a "ry=!ry:-=!"
  108. if !rx! geq !ry! (  REM 比较平
  109. if !x1! lss !x2! for /l %%i in (!x1!,1,!x2!) do (  REM 点1在左边
  110. set /a "ideal=(%y1%*(%x2%-%%i)+%y2%*(%%i-%x1%))/(%x2%-%x1%)"
  111. set "%~1_%%i_!ideal!=1"
  112. ) else if !x2! lss !x1! for /l %%i in (!x2!,1,!x1!) do (  REM 点2在左边
  113. set /a "ideal=(%y2%*(%x1%-%%i)+%y1%*(%%i-%x2%))/(%x1%-%x2%)"
  114. set "%~1_%%i_!ideal!=1"
  115. ) else (  REM 一个点
  116. set "%~1_!x1!_!y1!=1"
  117. )
  118. ) else (  REM 比较斜
  119. if !y1! lss !y2! for /l %%i in (!y1!,1,!y2!) do (  REM 点1在下边
  120. set /a "ideal=(%x1%*(%y2%-%%i)+%x2%*(%%i-%y1%))/(%y2%-%y1%)"
  121. set "%~1_!ideal!_%%i=1"
  122. ) else if !y2! lss !y1! for /l %%i in (!y2!,1,!y1!) do (  REM 点2在下边
  123. set /a "ideal=(%x2%*(%y1%-%%i)+%x1%*(%%i-%y2%))/(%y1%-%y2%)"
  124. set "%~1_!ideal!_%%i=1"
  125. ) else (  REM 一个点
  126. set "%~1_!x1!_!y1!=1"
  127. )
  128. )
  129. exit /b
复制代码

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

TOP

我记得指针时钟有人发过呀!#@¥@#¥……
综合型编程论坛
Writing Code That Nobody Else Can Read.

TOP

回复 2楼 的帖子

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

像这个:
000
      000
             000

上次qzwqzw弄了个改注册表之类的可以控制 字符大小,那个顶~
综合型编程论坛
Writing Code That Nobody Else Can Read.

TOP

回复 2楼 的帖子

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

TOP

返回列表