[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[特效代码] 分形图:谢尔宾斯基地毯

本帖最后由 a20150604 于 2017-4-13 13:02 编辑

有点闲, 想画点简单的平面分形图, 就先画个 谢尔宾斯基地毯 吧


这个图形是左右, 上下, 中心对称的, 用图形复制的方法是很快的
  1. REM Sierpinski carpet call 递归图形复制高速版
  2. %1 @goto :initCON
  3. @echo off & setlocal enabledelayedexpansion
  4. set /a "w=83,h=83, h1=h,t=w*h,xc=w/2+1,yc=h/2"
  5. set "TAB= " & for /F %%a in ('"prompt $h&for %%b in (1) do rem"')do Set "BS=%%a"
  6. set /a "buffwid = w, linesWantBackAbove = h + 1 - 1, cntBS = 2 + (buffwid + 7) / 8 * linesWantBackAbove"
  7. set "BSs=" & for /L %%a in (1 1 !cntBS!) do set "BSs=!BSs!%BS%"
  8. set "aLineBS=" & for /L %%a in (1 1 !w!) do set "aLineBS=!aLineBS!%BS%"
  9. mode %w%,%h1%
  10. for /l %%i in (1 1 !t!) do set "s=!s! "
  11. call :f 0 0 81 s
  12. REM <nul set /p "=!aLineBS!" & (2>nul echo;%TAB%!BSs!) & <nul set /p "=%BS%"
  13. REM <nul set /p "=%BS%!s:~0,-1!"
  14. title complete & >nul pause &exit
  15. :f xcnt ycnt hei s
  16. setlocal
  17. set "s=!%4!"
  18. if %3 leq 1 (
  19.     set /a "i=%1-xc + (%2-yc) * w + 1, L=i-1"
  20.     for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!#!s:~%%b!)
  21. ) else (
  22.     set /a "h=%3 / 3"
  23.     set /a "x=%1 + - h, y=%2 + - h"
  24.     call :f !x! !y! !h! %4
  25.     set /a "x1=%1 + (- %3/2), y1=%2 + (- %3/2), xb=x1+h, yb=y1+h"
  26.     for %%x in (- 0^& +) do for %%y in (- 0^& +) do (
  27.         if "%%x%%y" neq "0&0&" if "%%x%%y" neq "--" (
  28.             set /a "x2=xb + (%%x h), y2=yb + (%%y h)"
  29.             for /L %%j in (1 1 !h!) do (
  30.                 set /a "i=x2-xc + (y2-yc + %%j-1) * w + h, L=i-h, i1=x1-xc + (y1-yc + %%j-1) * w"
  31.                 for /f "tokens=1-4" %%a in ("!L! !i! !i1! !h!") do (
  32.                     set "s=!s:~0,%%a!!s:~%%c,%%d!!s:~%%b!"
  33.                     <nul set /p "=!aLineBS!" & (2>nul echo;%TAB%!BSs!) & <nul set /p "=%BS%"
  34.                     <nul set /p "=%BS%!s:~0,-1!"
  35.                 )
  36.             )
  37.         )
  38.     )
  39. )
  40. (
  41.     endlocal
  42.     set "%4=%s%"
  43.     exit /b
  44. )
  45. :initCON
  46. @echo off
  47. for %%a in (  FontSize:00080008      FontFamily:00000030  WindowSize:00C800C8
  48.               ScreenColors:0000000f  CodePage:000001b5    ScreenBufferSize:00C800C8
  49. ) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do (
  50.   >nul reg add HKCU\Console\Sierpinski_carpet /v %%b /t reg_dword /d 0x%%c /f
  51. )
  52. start "Sierpinski_carpet" /max "%ComSpec%" /c "%~0" REM & (call :delReg) & exit
  53. REM end of :initCON
  54. exit /b
  55. :delReg
  56. setlocal enabledelayedexpansion
  57. set "s=!time:~-4,1!"
  58. :delReg.loop
  59. set /a "elapse = (1!time:~-4,1! - s) %% 10"
  60. if %elapse% lss 2 goto :delReg.loop
  61. >nul reg delete HKCU\Console\Sierpinski_carpet /f
  62. endlocal
  63. exit /b
  64. REM end of :delReg
复制代码
for 模拟递归版
  1. %1 @goto :initCON
  2. @echo off & setlocal enabledelayedexpansion
  3. call :clearVars
  4. set /a "w=83,h=83, h1=h,t=w*h,xc=w/2+1,yc=h/2"
  5. mode %w%,%h1%
  6. set "TAB= " & for /F %%a in ('"prompt $h&for %%b in (1) do rem"')do Set "BS=%%a"
  7. set /a "buffwid = w, linesWantBackAbove = h + 1 - 1, cntBS = 2 + (buffwid + 7) / 8 * linesWantBackAbove"
  8. set "BSs=" & for /L %%a in (1 1 !cntBS!) do set "BSs=!BSs!%BS%"
  9. set "aLineBS=" & for /L %%a in (1 1 !w!) do set "aLineBS=!aLineBS!%BS%"
  10. for /l %%i in (1 1 !t!) do set "s=!s! "
  11. REM 堆栈 xSt, ySt, hSt, iSt 都取 4 位一节
  12. set "xL=- + + - 0&0&- + "
  13. set "yL=- + - + - + 0&0&"
  14. set /a "xcnt=0, ycnt=0, hei=81, istep=-2"
  15. :enter
  16. for /L %%* in () do (
  17.         <nul set /p "=!aLineBS!" & (2>nul echo;%TAB%!BSs!) & <nul set /p "=%BS%"
  18.         <nul set /p "=%BS%!s:~0,-1!"
  19.         REM if 层终结条件 满足
  20.         if !hei! leq 1 (
  21.             REM 层终结计算
  22.             set /a "i=xcnt-xc + (ycnt-yc) * w + 1, L=i-1"
  23.             for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!#!s:~%%b!)
  24.             REM 参数出栈
  25.             set /a "xcnt=!xSt:~-4!, ycnt=!ySt:~-4!, hei=!hSt:~-4!, istep=!iSt:~-4!"
  26.             set "xSt=!xSt:~0,-4!"
  27.             set "ySt=!ySt:~0,-4!"
  28.             set "hSt=!hSt:~0,-4!"
  29.             set "iSt=!iSt:~0,-4!"
  30.             REM goto :enter
  31.         ) else (
  32.         REM else
  33.             REM if 本层子计算未完成
  34.             if !istep! lss 14 (
  35.                 REM 生成 并更新 下一个(或第1个)子计算 的 参数
  36.                 if !istep! geq 0 (
  37.                     REM 还原上层中心坐标
  38.                     for %%i in (!istep!) do set /a "xcnt-=(!xL:~%%i,2! hei/3), ycnt-=(!yL:~%%i,2! hei/3)"
  39.                 )
  40.                 set /a "istep+=2"
  41.                 for %%i in (!istep!) do set /a "xcnt+=(!xL:~%%i,2! hei/3), ycnt+=(!yL:~%%i,2! hei/3)"
  42.                 REM 参数入栈
  43.                 set "t=!xcnt!   !ycnt!"
  44.                 set "xSt=!xSt!!t:~0,4!"
  45.                 set "ySt=!ySt!!t:~-4!"
  46.                 set "t=!istep!   !hei!"
  47.                 set "hSt=!hSt!!t:~-4!"
  48.                 set "iSt=!iSt!!t:~0,4!"
  49.                 REM 层递进一
  50.                 set /a "hei/=3, istep=-2"
  51.                 REM goto :enter
  52.             ) else (
  53.             REM else
  54.                 REM if 栈空
  55.                 if "!hSt!"=="" (
  56.                     REM goto :complete
  57.                     <nul set /p "=!aLineBS!" & (2>nul echo;%TAB%!BSs!) & <nul set /p "=%BS%"
  58.                     <nul set /p "=%BS%!s:~0,-1!"                    
  59.                     title complete any to exit... &  >nul pause &exit
  60.                 ) else (
  61.                 REM else
  62.                     REM 参数出栈
  63.                     set /a "xcnt=!xSt:~-4!, ycnt=!ySt:~-4!, hei=!hSt:~-4!, istep=!iSt:~-4!"
  64.                     set "xSt=!xSt:~0,-4!"
  65.                     set "ySt=!ySt:~0,-4!"
  66.                     set "hSt=!hSt:~0,-4!"
  67.                     set "iSt=!iSt:~0,-4!"
  68.                     REM goto :enter
  69.                 )
  70.             )
  71.         )
  72. )
  73. :complete
  74. exit
  75. :initCON
  76. @echo off
  77. for %%a in (  FontSize:00080008      FontFamily:00000030  WindowSize:00C800C8
  78.               ScreenColors:0000000f  CodePage:000001b5    ScreenBufferSize:00C800C8
  79. ) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do (
  80.   >nul reg add HKCU\Console\Sierpinski_carpet /v %%b /t reg_dword /d 0x%%c /f
  81. )
  82. start "Sierpinski_carpet" /max "%ComSpec%" /c "%~0" REM & (call :delReg) & exit
  83. REM end of :initCON
  84. exit /b
  85. :clearVars
  86. set "Path=%SystemRoot%\system32"
  87. for /f "delims==" %%a in ('set') do (
  88.   if /i "%%a" neq "Path" set "%%a="
  89. )
  90. exit /b
  91. REM end of :clearVars
复制代码
call 递归版:
  1. %1 @goto :initCON
  2. @echo off & setlocal enabledelayedexpansion
  3. call :clearVars
  4. set /a "w=83,h=83, h1=h+1,t=w*h,xc=w/2+1,yc=h/2-1"
  5. mode %w%,%h1%
  6. for /l %%i in (1 1 !t!) do set "s=!s! "
  7. call :f 0 0 81 s
  8. echo;!s! &pause &exit
  9. :f xcnt ycnt hei s
  10. setlocal
  11. set "s=!%4!"
  12. if %3 leq 1 (
  13.     set /a "i=%1-xc + (%2-yc) * w + 1, L=i-1"
  14.     for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!#!s:~%%b!)
  15.     cls & echo;!s!
  16. ) else (
  17.     set /a "h=%3 / 3"
  18.     for %%x in (- 0^& +) do for %%y in (- 0^& +) do (
  19.         if "%%x%%y" neq "0&0&" (
  20.             set /a "x=%1 + (%%x h), y=%2 + (%%y h)"
  21.             call :f !x! !y! !h! %4
  22.         )
  23.     )
  24. )
  25. (
  26.     endlocal
  27.     set "%4=%s%"
  28.     exit /b
  29. )
  30. :d
  31. set /a "i=%1-xc + (%2-yc) * w + 1, L=i-1"
  32. for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!#!s:~%%b!)
  33. exit /b
  34. :initCON
  35. @echo off
  36. for %%a in (  FontSize:00080008      FontFamily:00000030  WindowSize:00C800C8
  37.               ScreenColors:0000000f  CodePage:000001b5    ScreenBufferSize:00C800C8
  38. ) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do (
  39.   >nul reg add HKCU\Console\Sierpinski_carpet /v %%b /t reg_dword /d 0x%%c /f
  40. )
  41. start "Sierpinski_carpet" /max "%ComSpec%" /c "%~0" REM & (call :delReg) & exit
  42. REM end of :initCON
  43. exit /b
  44. :clearVars
  45. set "Path=%SystemRoot%\system32"
  46. for /f "delims==" %%a in ('set') do (
  47.   if /i "%%a" neq "Path" set "%%a="
  48. )
  49. REM set path=
  50. exit /b
  51. REM end of :clearVars
复制代码
goto 递归版, 没有期望的的速度, 毕竟 goto 要在文件中搜索行标, 快不了
  1. %1 @goto :initCON
  2. @echo off & setlocal enabledelayedexpansion
  3. call :clearVars
  4. set /a "w=83,h=83, h1=h+1,t=w*h,xc=w/2+1,yc=h/2-1"
  5. mode %w%,%h1%
  6. for /l %%i in (1 1 !t!) do set "s=!s! "
  7. REM 堆栈 xSt, ySt, hSt, iSt 都取 4 位一节
  8. set "xL=- + + - 0&0&- + "
  9. set "yL=- + - + - + 0&0&"
  10. set /a "xcnt=0, ycnt=0, hei=81, istep=-2"
  11. :enter
  12.     cls & echo;!s!
  13.         REM if 层终结条件 满足
  14.         if !hei! leq 1 (
  15.             REM 层终结计算
  16.             set /a "i=xcnt-xc + (ycnt-yc) * w + 1, L=i-1"
  17.             for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!#!s:~%%b!)
  18.             REM 参数出栈
  19.             set /a "xcnt=!xSt:~-4!, ycnt=!ySt:~-4!, hei=!hSt:~-4!, istep=!iSt:~-4!"
  20.             set "xSt=!xSt:~0,-4!"
  21.             set "ySt=!ySt:~0,-4!"
  22.             set "hSt=!hSt:~0,-4!"
  23.             set "iSt=!iSt:~0,-4!"
  24.             goto :enter
  25.         ) else (
  26.         REM else
  27.             REM if 本层子计算未完成
  28.             if !istep! lss 14 (
  29.                 REM 生成 并更新 下一个(或第1个)子计算 的 参数
  30.                 if !istep! geq 0 (
  31.                     REM 还原上层中心坐标
  32.                     for %%i in (!istep!) do set /a "xcnt-=(!xL:~%%i,2! hei/3), ycnt-=(!yL:~%%i,2! hei/3)"
  33.                 )
  34.                 set /a "istep+=2"
  35.                 for %%i in (!istep!) do set /a "xcnt+=(!xL:~%%i,2! hei/3), ycnt+=(!yL:~%%i,2! hei/3)"
  36.                 REM 参数入栈
  37.                 set "t=!xcnt!   !ycnt!"
  38.                 set "xSt=!xSt!!t:~0,4!"
  39.                 set "ySt=!ySt!!t:~-4!"
  40.                 set "t=!istep!   !hei!"
  41.                 set "hSt=!hSt!!t:~-4!"
  42.                 set "iSt=!iSt!!t:~0,4!"
  43.                 REM 层递进一
  44.                 set /a "hei/=3, istep=-2"
  45.                 goto :enter
  46.             ) else (
  47.             REM else
  48.                 REM if 栈空
  49.                 if "!hSt!"=="" (
  50.                     goto :complete
  51.                 ) else (
  52.                 REM else
  53.                     REM 参数出栈
  54.                     set /a "xcnt=!xSt:~-4!, ycnt=!ySt:~-4!, hei=!hSt:~-4!, istep=!iSt:~-4!"
  55.                     set "xSt=!xSt:~0,-4!"
  56.                     set "ySt=!ySt:~0,-4!"
  57.                     set "hSt=!hSt:~0,-4!"
  58.                     set "iSt=!iSt:~0,-4!"
  59.                     REM goto :enter
  60.                     goto :enter
  61.                 )
  62.             )
  63.         )
  64. :complete
  65. echo;!s! &pause &exit
  66. :d
  67. title xcnt=%1, ycnt=%2
  68. set /a "i=%1-xc + (%2-yc) * w + 1, L=i-1"
  69. for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!#!s:~%%b!)
  70. exit /b
  71. :initCON
  72. @echo off
  73. for %%a in (  FontSize:00080008      FontFamily:00000030  WindowSize:00C800C8
  74.               ScreenColors:0000000f  CodePage:000001b5    ScreenBufferSize:00C800C8
  75. ) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do (
  76.   >nul reg add HKCU\Console\Sierpinski_carpet /v %%b /t reg_dword /d 0x%%c /f
  77. )
  78. start "Sierpinski_carpet" /max "%ComSpec%" /c "%~0" REM & (call :delReg) & exit
  79. REM end of :initCON
  80. exit /b
  81. :clearVars
  82. set "Path=%SystemRoot%\system32"
  83. for /f "delims==" %%a in ('set') do (
  84.   if /i "%%a" neq "Path" set "%%a="
  85. )
  86. REM set path=
  87. exit /b
  88. REM end of :clearVars
复制代码
4

评分人数

说好的 :delReg 去哪了...

TOP

回复 2# CrLf

第二部也许出吧

TOP

it is cool~~~~~~~~~

TOP

返回列表