本帖最后由 a20150604 于 2017-5-2 02:28 编辑
- @echo off & setlocal enableDelayedExpansion
-
- REM 方向运算
- set "D=y+=bw2" & set "U=y-=bw2" & set "L=x-=bw2" & set "R=x+=bw2"
-
- for /L %%T in (1 1 6) do (
- REM 向量总长: 4 * ( 1<<(iterations-1)*2 ) - 1
- REM set /a "iterations=4, basewid=6, bw2=basewid*2, hei=wid=basewid*4*(1<<iterations-1), x=xs=wid*1/(4*(1<<iterations-1)), y=ys=wid-xs, imax = 4 * ( 1<<(iterations-1)*2 ) - 1 - 1"
- set /a "hei=wid=256*2, iterations=%%T"
- set /a "basewid=wid/(4*(1<<iterations-1)), bw2=basewid*2, x=xs=wid*1/(4*(1<<iterations-1)), y=ys=wid-xs, imax = 4 * ( 1<<(iterations-1)*2 ) - 1 - 1"
-
- set "C="
- set "R_C="
-
- echo;C=!C!
- echo;R_C=!R_C!
-
- for /L %%i in (1 1 !iterations!) do (
-
- set "CW=!C!"
- set "AC=!C!"
-
- set "R_CW=!R_C!"
- set "R_AC=!R_C!"
-
- if "!C!" neq "" (
-
- REM 顺旋:
- REM R->T, U->R, L->U, D->L, T->D
- set "CW=!CW:R=T!"
- set "CW=!CW:U=R!"
- set "CW=!CW:L=U!"
- set "CW=!CW:D=L!"
- set "CW=!CW:T=D!"
-
- REM 逆旋:
- REM L->T, U->L, R->U, D->R, T->D
- set "AC=!AC:L=T!"
- set "AC=!AC:U=L!"
- set "AC=!AC:R=U!"
- set "AC=!AC:D=R!"
- set "AC=!AC:T=D!"
-
-
- REM 顺旋:
- REM R->T, U->R, L->U, D->L, T->D
- set "R_CW=!R_CW:R=T!"
- set "R_CW=!R_CW:U=R!"
- set "R_CW=!R_CW:L=U!"
- set "R_CW=!R_CW:D=L!"
- set "R_CW=!R_CW:T=D!"
-
- REM 逆旋:
- REM L->T, U->L, R->U, D->R, T->D
- set "R_AC=!R_AC:L=T!"
- set "R_AC=!R_AC:U=L!"
- set "R_AC=!R_AC:R=U!"
- set "R_AC=!R_AC:D=R!"
- set "R_AC=!R_AC:T=D!"
- )
-
- set "C=!R_CW!U!C!R!C!D!R_AC!"
-
- REM 逆时针90度正行 + 上 + 逆行 + 左 + 逆行 + 下 + 顺时针90度正行
- set "R_C=!AC!U!R_C!L!R_C!D!CW!"
-
- echo;C=!C!
- )
-
- <nul >Hilbert_curve%%T.htm (
- echo;^<svg height="!hei!" width="!wid!"^>
- set /p "=<polyline points=""
- set /p "=!x!,!y! "
- for /L %%i in (0 1 !imax!) do (
- for %%m in ("!C:~%%i,1!") do (
- set /a "!%%~m!"
- set /p "=!x!,!y! "
- )
- )
- echo;"
- set /p "=style="fill:none;stroke:red;stroke-width:1"/>"
- echo;Sorry, your browser does not support inline SVG.
- echo;^</svg^>
- )
-
- start "" Hilbert_curve%%T.htm
-
- )
-
- title any key to exit...
- >nul pause
-
- exit /b
复制代码
|