从实验来看 ,把退格符后面的内容理解为车。把退格符号理解为车走的路程。而原来的字符理解为路,车过了,路还是路。我是这样认为的。-
-
- @echo off&setlocal enabledelayedexpansion&cls&color 0a
- echo 居中显示70个小方块
- for /l %%1 in (1 1 80) do (set "space= !space!")
- for /l %%2 in (1 1 10 ) do echo.
- set /p=!space:~,-54!<nul
- rem 实现向右平移26byte,注释掉就将从最左面开始
- for /l %%i in (1 1 70) do (
- set /a "mod=%%i%%14"
- set /a n=n+1
- set /p=■<nul
- if !mod!==0 (set /p=!space:~,-28!<nul)
- for /l %%1 in (1 1 50) do (call echo.>nul)
- )
- exit /b
复制代码 一个显而易见的原理------
cmd一行可以显示80个byte,如果这一行已经填满,这时如果你插入x<80个字符,这时此行就会有x个字符被挤出来,插如多少就挤出多少,挤出的字符就自动到了第二行。根据这个原理,利用语句set /p=!space:~,-54!<nul就轻松的实现了平移。
----------求余运算与周期性运动
求余运算可以很好的刻画周期性运动,这个实例保持了总行高不变。改动一下就可以模仿自由落体运动。
- @echo off&setlocal enabledelayedexpansion&cls&color 1a
- rem 反复向上爬升
- for /l %%1 in (1 1 80) do (set "space= !space!")
- for /l %%i in (1 1 100) do (
- cls
-
- set /a "mod=%%i%%23"
- for /l %%j in (!mod! 1 23) do echo.
- for /l %%k in (1 1 !mod!) do echo !space:~70!■
- set /a n+=1
- for /l %%1 in (1 1 50) do (call echo.>nul)
- )
- :end
- echo %n%
- exit /b
复制代码
- rem 居中显示到三角
- @echo off&setlocal enabledelayedexpansion&cls&color 1a
- for /l %%1 in (1 1 80) do (set "space= !space!")
- for /l %%i in (1 1 9) do echo.
- for /l %%i in (1 1 5) do (
- set /p=!space:~-30!<nul
- for /l %%i in (1 1 !mod!) do set /p=!space:~-2!<nul
- set /a "t=12-2*%%i"
- set /a "mod=%%i%%5"
- for /l %%i in (1 1 !t!) do (
- set /p=■<nul
- )
- for /l %%1 in (1 1 50) do (call echo.>nul)
- echo.
- )
- pause >nul
复制代码
记得读大学时,我们的计算机进行抽签考试,我就抽到了这个到三角,要求在5分钟内编程显示,我在机房里
半天也没编出程序来,眼看时间就要到了,在最后的一分钟我来了灵感才编出程序来。当时考试差点没过关,今天我试着用bat编写了一个,算是对自己读书时代的怀念。我习惯于定义空格,好象这样做规范一点,因为我常拿到
其它的bat,稍微动了一书写个格式,程序就报错,其根本就是没定义空格。
创意----刷屏语句-不用cls也可以实现从下到上运动,因为cmd默认显示300行,利用这点就可以实现从下到上的运动。每屏应该是25行。- rem 刷屏语句 for /l %%j in (1 1 300) do (echo.)
-
- for /l %%i in (1 1 20) do (
- for /l %%j in (1 1 300) do (echo.)
- for /l %%j in (1 1 %%i) do (echo ■ )
- echo.&echo.&echo.
- for /l %%1 in (1 1 100) do call echo.>nul
-
- )
复制代码
- @echo off&setlocal enabledelayedexpansion&cls&color 0a
- rem 利用刷屏,实现向右运动,不过要用pause才好
- for /l %%1 in (1 1 80) do set "space= !space!"
- for /l %%i in (1 1 20) do (
- for /l %%j in (1 1 25) do (echo.)
- set tt=!space:~-%%i!■
- echo !tt!
- for /l %%k in (1 1 13) do echo.
- for /l %%1 in (1 1 50) do call echo.>nul
- )
-
- pause>nul
复制代码
-
- @echo off&setlocal enabledelayedexpansion&cls&color 0a
- rem 利用刷屏,实现向左运动,不过要用pause才好
- for /l %%1 in (1 1 80) do set "space= !space!"
- for /l %%i in (1 1 70) do (
- for /l %%j in (1 1 25) do (echo.)
- set /a n=78-%%i
- call set sp=%%space:~-!n!%%
- echo !sp!●
- for /l %%k in (1 1 13) do echo.
- for /l %%1 in (1 1 50) do call echo.>nul
- )
- pause>nul
复制代码
-
- @echo off&setlocal enabledelayedexpansion&cls&color 0a
- rem 利用刷屏,实现向下运动,不过要用pause才好
- for /l %%1 in (1 1 80) do set "space= !space!"
- for /l %%i in (1 1 25) do (
- for /l %%j in (1 1 25) do (echo.)
- set /a h=25-%%i
-
- echo !space:~-39!●
- for /l %%k in (1 1 !h!) do echo.
- for /l %%1 in (1 1 50) do call echo.>nul
- )
- pause>nul
复制代码
- @echo off &setlocal enabledelayedexpansion
- rem 转载 by 523066680 这段代码很简洁,值得学习。
-
-
- for /l %%a in (1,1,79) do (set "space= !space!")
- for /l %%a in (1,1,23) do (set h%%a=%space%)
-
- set /p input="输入高[2-23]: "
- set /a c=0,h=1,i2=input*2,na=40-input
- set stra=!space:~-%na%!
-
- for %%a in ("c + %i2%" "h + %input%" "c - 1" "h - 1") do (call :func %%~a)
-
- pause>nul
- exit /b
-
- :func
- set /a %1 %2 = 1,cf=c-1
- set h%h%=!h%h%:~0,%cf%!.!h%h%:~%c%!
- ping -n 1 127.1>nul &cls
- for /l %%a in (1,1,%input%) do (echo,%stra%!h%%a:~0,-%na%!)
- if !%1! neq %3 goto :func
复制代码
- @echo off &setlocal enabledelayedexpansion&cls&color 1a
- rem 抛物线x=y*y与y=x*x
- for /l %%1 in (1 1 80) do set "space= !space!"
- mode con cols=80 lines=50
- for /l %%i in (0 1 5) do (
- set y=%%i
- set /a "x=y*y"
- call echo %%space:~-!x!%%●
- )
- echo --------
- for /l %%i in (0 1 4) do (
- set x=%%i
- set /a "x2=12*x"
- rem 这句话是把x轴的单位换成y轴的单位的12倍,是为了美观。即两轴的单位不等。
- rem 在数学上这是容许的
- set /a "y.increase=2*x+1"
- for /l %%j in (1 1 !y.increase!) do echo.
- call echo %%space:~-!x2!%%●
- )
- goto:eof
复制代码
- @echo off &setlocal enabledelayedexpansion&cls&color 1a
- rem 逐渐显示与删除文字
- set char=我写的这个有点烂,管它的这只是我的一次作业。
- for /l %%i in (1 1 21) do (
- set /p=!char:~,%%i!<nul
- ping -n 2 localhost >nul
- cls
- )
- for /l %%i in (1 1 21) do (
- set /p=!char:~,-%%i!<nul
- ping -n 2 localhost >nul
- cls
- )
- for /l %%i in (1 1 21) do (
- set /a "s=%%i-1"
- call echo %%char:~!s!,1%%<nul
- ping -n 2 localhost >nul
- cls
- )
复制代码
- @echo off &setlocal enabledelayedexpansion&cls&color 1a
- rem 设置环境变量char
- for /f %%i in ('more +6 %~f0') do set char=%%i
- echo ~~~~~%char%~~~~~
- pause
- exit /b
- 1这样也可以设置环境变量 这样也可以设置环境变量
- 2这样也可以设置环境变量 这样也可以设置环境变量
复制代码
- @echo off &setlocal enabledelayedexpansion &cls &color 1a
- for /l %%1 in (1 1 80) do set "space= !space!"
- more /s +14 %~f0>rr.txt
- for /l %%i in (1 1 50) do (
- for /f "eol=e tokens=* " %%i in (rr.txt) do echo %%i
- for /l %%1 in (1 1 100) do call echo.>nul
- cls
- for /f "eol=m tokens=* " %%i in (rr.txt) do echo %%i
- for /l %%1 in (1 1 100) do call echo.>nul
- cls
- )
- del rr.txt
- pause
- exit /b
- e _,._
- e __.' _)
- e <_,)'.-"a\
- e /' ( \
- e _.-----..,-' (`"--^
- e // |
- e (| `; , |
- e \ ;.----/ ,/
- e ) // / | |\ \
- e \ \\`\ | |/ /
- e \ \\ \ | |\/
- e `" `" `"`
-
- m _,._
- m __.' _)
- m <_,)'.-"a\
- m /' ( \
- m _.-----..,-' (`"--^
- m // |
- m (| `; , |
- m \ ;.----/ ,/
- m ) // / \ \ |
- m | |\ \ / / |
- m | | \/ \/| |
- m `"` `"`
- ──────────────────────────────
复制代码
[ 本帖最后由 myzwd 于 2009-3-22 12:31 编辑 ] |