本帖最后由 cutebe 于 2013-5-13 23:23 编辑
变量说明,有兴趣的朋友可以深入看下
FUL 用于公式:SUF=(COL-1)%%8,这里公式略有变形
AFT 接上,公式变形后作为计算SUF的中间变量
FS 满足条件:"(COL-1)%%8=0" 的标识(FLAG),满足条件时为-1,否则为0
FF 同上标识,结果不同(1,0)
PRP 计算前置空格数量公式变化后的中间变量
SAP 一列除去后置空格后的长度
SEG 前、后置空格将去掉后的长度
ONE 回到上一行相同位置退了几步
LDP 字符串长度与前置空格的差,计算CUR的中间变量
CUR 当前行回走到上一行前退的步数
TL 标记行是否等于ROW-1的中间变量
FW 标识ROW-1(-1,0),是不是最后一行
FR 标识ROW-1(1,0),同上
FW2 标识ROW-2(-1,0),用于"(COL-1)%%8=0"时的判断,是不是倒数第二行
F2 联合标记(ROW-1)(ROW-2)中间变量(-N)
FK 联合标识(-1,0),是不是最后两行,用于计算空格数
FE 联合标识(0,1),用于取消回走前的字符串输出
FL 联合标识(1,0),同FK
LE2 取消空格时,此变量为0
X2 回到原点后,向下走的行数,走到指定行下一行或同一行
TC 具体回走时,指定行回走的总长,同时用于判断Y坐标是否在后置空格SUF范围内
FC 列坐标Y在后置空格SUF内的标识(-1,0)
FX 同上(0,1)
FM 同上(1,0)
FP 用于"(COL-1)%%8=0"时的判断
TD 指定行回走的步数,配合TAB
TM 指定行单独回走的格数
不会写特效,见笑了。- @ECHO OFF
- MODE CON COLS=48 LINES=10
- SETLOCAL ENABLEDELAYEDEXPANSION
- CALL :PREVAR 先导标签,即调用SETXY前先调用一次,且只需要一次。
- SET/aRO1=ROW-1,CO8=COL-8
- :LP 输入坐标演示
- SET/aRAN=!RANDOM!%%RO1+1,RA2=!RANDOM!%%CO8+9,RS=!RANDOM!%%9
- CALL :SETXY RAN RA2
- SET STR=
- SET/p=!STR:~%RS%,1!<NUL
-
- TITLE 光标定位 (%RAN%,%RA2%) (总行列:%ROW%,%COL%)
- SET "TXT=(%X%,%Y%)%SP:~,8%"
- SET/p=<NUL
- GOTO :LP
- ::结束
-
-
- :PREVAR 先导变量,占用名:T B ROW COL FS FF SUF LEN STP PRE SAP SEG ONE CUR UP
- SET JSF="%TMP%\TAB.JS"
- IF NOT EXIST %JSF% ECHO=WScript.echo(String.fromCharCode(9));>%JSF%
- FOR /F "DELIMS=" %%T IN ('CSCRIPT //NOLOGO %JSF%')DO SET "T=%%T"
- SET "B="
- FOR /F "SKIP=3 TOKENS=2" %%V IN ('MODE CON')DO (
- SET/aN+=1
- SET VAR!N!=%%V
- )
- SET/aROW=VAR1,COL=VAR2,COL2=COL*2
- FOR /L %%I IN (0,1,%COL2%)DO SET "K=%B%!K!"&SET "SP= !SP!"
- SET/a"FUL=COL-1,AFT=FUL%%8,FS=(AFT-1)>>3,FF=FS&1,SUF=(FUL+FF)%%8"
- SET/aLEN=%RANDOM%%%8*(FS+1)+FF*FUL
- SET/aSTP=8-LEN%%8,PRP=(COL-SUF)%%STP,PRE=PRP-8*FS
- SET/aSAP=COL-SUF,SEG=SAP-PRE,ONE=SEG/STP+1,LDP=LEN-PRE
- SET/aCUR=LDP/STP+(LDP%%STP+PRP)/STP+1,UP=ONE+CUR
- GOTO :EOF
-
- :SETXY X Y 跳到指定坐标
- SET/aX=%1,Y=%2
- SET/a"TL=ROW-X-1,FW=TL>>7,FR=FW&1,FW2=(TL-1)>>7"
- SET/a"F2=TL*FR+FF*FW2*(FW+1),FK=F2>>7,FE=FK+1,FL=FK&1,LE2=LEN*FE,X2=X+F2"
- SET/a"TC=SAP-Y+1,FC=TC>>9,FX=FC+1,FM=FC&1,FP=Y-2>>9&1"
- SET/aTD=TC/STP*FX,TM=TC%%STP*FX-TC*FM
- SET/a"SAPF=CUR+1+TD-FF*FP,SPN=TC*FC*FE+FL*(Y-1),BKN=(TM+8*FF*FP)*(FX&FE)"
- SET/P=!K:~-%COL%,-1!<NUL
- FOR /L %%T IN (1,1,%ROW%)DO (%原点%
- SET/P=!SP:~,%LEN%!<NUL
- SET/P=%T%!K:~,%UP%!<NUL
- SET/P=!K:~,%PRE%!<NUL
- )
- FOR /L %%B IN (1,1,%X2%)DO ECHO,%指定行或下一行%
- SET/P=!SP:~,%LE2%!<NUL%指定行列%
- SET/P=!T:~,%FE%!!K:~,%SAPF%!<NUL
- SET/P=!SP:~,%SPN%!!K:~,%BKN%!<NUL
- GOTO :EOF
复制代码 这个有点样子- ::花边
- ::CODE BY cutebe AT BBS.BATHOME.NET
- @ECHO OFF
- SETLOCAL ENABLEDELAYEDEXPANSION
- SET/aCOLS=50,LINES=20
- MODE CON LINES=%LINES% COLS=%COLS%
- TITLE 光标定位 效果演示
- CALL :PREVAR
-
- ::开始
- SET STR= ☆★○●◎◇◆□■△▲
- SET/aXA=1,YA=9,XB=19,YB=49,XR=XA,YR=YA,LONG=(XB-XA+YB/2-YA/2)*2
-
- FOR /L %%I IN (1 1 21)DO (
- FOR /L %%J IN (1 1 %LONG%)DO (
- CALL :SETXY XR YR
- SET/a"MOD=%%I%%2*(%%I/2+1)"
- FOR %%K IN (!MOD!)DO SET/p=!STR:~%%K,1!<NUL
- SET/a"FX1=XR-XB>>7,FX2=XA-XR>>7,FY1=YR-YB>>7,FY2=YA-YR>>7"
- SET/a"XR+=(FY1+1)*FX2-(FY2+1)*FX1,YR+=2*((FX2+1)*FY2-(FX1+1)*FY1)"
- )
- )
- CALL :SETXY 9 20
- PAUSE
- GOTO :EOF
- ::结束
-
- :PREVAR 先导变量,占用名:T B ROW COL FS FF SUF LEN STP PRE SAP SEG ONE CUR UP
- SET JSF="%TMP%\TAB.JS"
- IF NOT EXIST %JSF% ECHO=WScript.echo(String.fromCharCode(9));>%JSF%
- FOR /F "DELIMS=" %%T IN ('CSCRIPT //NOLOGO %JSF%')DO SET "T=%%T"
- SET "B="
- FOR /F "SKIP=3 TOKENS=2" %%V IN ('MODE CON')DO (
- SET/aN+=1
- SET VAR!N!=%%V
- )
- SET/aROW=VAR1,COL=VAR2,COL2=COL*2
- FOR /L %%I IN (0,1,%COL2%)DO SET "K=%B%!K!"&SET "SP= !SP!"
- SET/a"FUL=COL-1,AFT=FUL%%8,FS=(AFT-1)>>3,FF=FS&1,SUF=(FUL+FF)%%8"
- SET/aLEN=%RANDOM%%%8*(FS+1)+FF*FUL
- SET/aSTP=8-LEN%%8,PRP=(COL-SUF)%%STP,PRE=PRP-8*FS
- SET/aSAP=COL-SUF,SEG=SAP-PRE,ONE=SEG/STP+1,LDP=LEN-PRE
- SET/aCUR=LDP/STP+(LDP%%STP+PRP)/STP+1,UP=ONE+CUR
- GOTO :EOF
-
- :SETXY X Y 跳到指定坐标
- SET/aX=%1,Y=%2
- SET/a"TL=ROW-X-1,FW=TL>>7,FR=FW&1,FW2=(TL-1)>>7"
- SET/a"F2=TL*FR+FF*FW2*(FW+1),FK=F2>>7,FE=FK+1,FL=FK&1,LE2=LEN*FE,X2=X+F2"
- SET/a"TC=SAP-Y+1,FC=TC>>9,FX=FC+1,FM=FC&1,FP=Y-2>>9&1"
- SET/aTD=TC/STP*FX,TM=TC%%STP*FX-TC*FM
- SET/a"SAPF=CUR+1+TD-FF*FP,SPN=TC*FC*FE+FL*(Y-1),BKN=(TM+8*FF*FP)*(FX&FE)"
- SET/P=!K:~-%COL%,-1!<NUL
- FOR /L %%T IN (1,1,%ROW%)DO (%原点%
- SET/P=!SP:~,%LEN%!<NUL
- SET/P=%T%!K:~,%UP%!<NUL
- SET/P=!K:~,%PRE%!<NUL
- )
- FOR /L %%B IN (1,1,%X2%)DO ECHO,%指定行或下一行%
- SET/P=!SP:~,%LE2%!<NUL%指定行列%
- SET/P=!T:~,%FE%!!K:~,%SAPF%!<NUL
- SET/P=!SP:~,%SPN%!!K:~,%BKN%!<NUL
- GOTO :EOF
复制代码
|