Board logo

标题: [游戏娱乐] 批处理画圆 [打印本页]

作者: fatcat    时间: 2012-3-4 22:21     标题: 批处理画圆

本帖最后由 fatcat 于 2012-3-4 22:37 编辑

  1. @echo off & setlocal enabledelayedexpansion
  2. if "%1"=="" (
  3.   >nul reg add hkcu\Console\mpc /v FontSize /t reg_dword /d 0xc0006 /f
  4.   start "mpc" /max %comspec% /c %0 1&goto:eof
  5. ) else (>nul reg delete hkcu\Console\mpc /f)
  6. set /a sz=29, wid=2*sz+1, Cols=2*wid, iMax=wid*wid
  7. for /l %%i in (1 1 !iMax!) do set "scr= !scr!"
  8. set "emp=!scr!"
  9. color 0a & mode con cols=!Cols! lines=!wid!
  10. rem 取得以圆周轨迹为动态圆心坐标
  11. set /a xC=sz+1, yC=xC, r=14 & rem 指定圆心及半径
  12. set /a x=0, y=r, d=-r
  13. for /l %%i in (1 1 999) do (
  14.   set /a x%%i=x, y%%i=y
  15.   set /a x+=1, d+=1+(x"<<1)
  16.   if !d! geq 0 set /a y-=1, d-=y"<<1
  17.   if !y! lss !x! (set ie=%%i&goto :lb1)
  18. )
  19. :lb1
  20. title 动画模拟以圆周轨迹方式画一个圆
  21. set x=x&set y=y& set /a ib=1,step=1,ix=0,iy=2,ic=0,ict=-1
  22. for /l %%i in (0 1 7) do (
  23.   set /a "sx=(3-ix&-1)>>31|1, ix+=1, ix%%=8, sy=(3-iy&-1)>>31|1, iy+=1, iy%%=8, ic+=1, ic%%=2
  24.   if !ic! equ 0 (set tmp=!x!&set x=!y!& set y=!tmp!)
  25.   for /f "tokens=1,2" %%X in ("!x! !y!") do for /l %%i in (!ib! !step! !ie!) do (
  26.     set /a xd=!sx:1=!!%%X%%i!+xC, yd=!sy:1=!!%%Y%%i!+yC, ict+=1
  27.     set xc!ict!=!xd!& set yc!ict!=!yd!
  28.     set /a "inScr=(xd-1^xd-wid)&(yd-1^yd-wid)
  29.     if !inScr! lss 0 (
  30.       set /a ind=xd+yd*wid+1, lenL=ind-1, lenR=iMax-ind
  31.       for /f "tokens=1,2,3" %%a in ("!lenL! !ind! !lenR!") do (set scr=!scr:~0,%%a!·!scr:~%%b,%%c!)
  32.     )
  33.     cls &(<nul set /p=!scr:~0,-1!)
  34.   )
  35.   set tmp=!ib!&set ib=!ie!& set ie=!tmp!& set /a step=-step
  36. )
  37. pause
  38. title 随机生成一些圆或者弧
  39. set "scr=!emp!"
  40. set /a xC=25, yC=30, r=15
  41. for /l %%n in (1 1 5) do (
  42.   call :mpc
  43.   set /a "xC=!random!%%wid, yC=!random!%%wid, r=!random!%%(wid*2/3-10)+10"
  44. )
  45. cls &(<nul set /p=!scr:~0,-1!)
  46. pause
  47. title 圆的动画
  48. set r=14& set "scr=!emp!"
  49. set /a p1=-1, p2=p1+ict/3, p3=p1+2*ict/3, div=ict+1
  50. for /l %%i in (0 1 9999) do (
  51.   set "scr=!emp!"
  52.   set /a "p1+=1,p1%%=div,p2+=1,p2%%=div,p3+=1,p3%%=div"
  53.   for %%j in (!p1! !p2! !p3!) do (
  54.     set /a xC=!xc%%j!, yC=!yc%%j!
  55.     call :mpc
  56.   )
  57.   cls &(<nul set /p=!scr:~0,-1!)
  58. )
  59. pause
  60. exit
  61. :mpc rem midpoint circle algorithm 中点画圆算法
  62. set /a x=0, y=r, d=-r
  63. for /l %%i in (1 1 999) do (
  64.   for %%# in (1 2) do (
  65.     for %%x in (-!x! !x!) do for %%y in (-!y! !y!) do (
  66.       set /a xd=%%x+xC, yd=%%y+yC, "inScr=(xd-1^xd-wid)&(yd-1^yd-wid)
  67.       if !inScr! lss 0 (
  68.         set /a ind=xd+yd*wid+1, lenL=ind-1, lenR=iMax-ind
  69.         for /f "tokens=1,2,3" %%a in ("!lenL! !ind! !lenR!") do (set scr=!scr:~0,%%a!·!scr:~%%b,%%c!)
  70.       )
  71.     )
  72.     set tmp=!x!&set x=!y!& set y=!tmp!
  73.   )
  74.   set /a x+=1, d+=1+(x"<<1)
  75.   if !d! geq 0 set /a y-=1, d-=y"<<1
  76.   if !y! lss !x! exit /b
  77. )
  78. exit /b
复制代码





欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2