返回列表 发帖

【出题】显示移动文字的批处理函数

本帖最后由 plp626 于 2011-5-9 20:02 编辑

下面代码保存为test.html
<HTML>
  <BODY>
<marquee scrollamount=10 width=200  behavior=scroll>bbs.bathome.net</marquee> <P>
<marquee scrollamount=5 width=200  behavior=alternate>bbs.bathome.net</marquee> <P>
                <marquee scrollamount=15 width=200  behavior=slide>bbs.bathome.net</marquee>
  </BODY>
</HTML>COPY
现在用批处理分别实现上面scroll,alternate,slide三个效果:
call:marquee "scrollamount=10 width=200  behavior=scroll" "bbs.bathome.net"COPY
call:marquee "scrollamount=5 width=200  behavior=alternate" "bbs.bathome.net"COPY
call:marquee "scrollamount=15 width=200  behavior=slide" "bbs.bathome.net"COPY
移动文字通用函数,要求代码短小者为佳
:marquee <"属性"> <"字符串">
rem 等待你的实现。。。。
goto:eofCOPY
还有好多属性有待实现,比如:
<HTML>
  <BODY>
      <marquee scrollamount=5 width=400  direction=left>bbs.bathome.net</marquee> <P>
      <marquee scrollamount=10 width=400  direction=right>bbs.bathome.net</marquee> <P>
      <marquee scrollamount=15 width=400  direction=down>bbs.bathome.net</marquee> <P>
      <marquee scrollamount=20 width=400  direction=up>bbs.bathome.net</marquee> <P>
  </BODY>
</HTML>COPY
先看看大家的热情程度。
============================================
2011-5-9修订:
对于函数传递参数的格式不做硬性规定,

可以
call:marquee "scrollamount=15 width=200  behavior=slide" "bbs.bathome.net"COPY
也可以
::主要是考虑到字符串作为值传递的很多缺陷,所以鼓励大家引用调用(将字符串保持在变量内,把变量名传递到函数体内)
::用逗号隔开属性值的方式,是考虑到cmdset/a的特性,方便赋值。
set str=bbs.bathome.net
call:marquee "scrollamount=15, width=200, behavior=slide" str COPY
初衷是:让调用者觉得方便,同时又让函数的实现代码尽量简短(这个函数无需考虑效率问题)
============================================
看到大家有在函数内部求字符串长度的“操作”,我的观点是在参数传递时,可以把字符串的长度作为参数传递过去,这样可以保持marquee函数功能的单一,最大限度做到函数的复用。
set Mystr=bbs.bathome.net
call:strlen Mystr len
call:marquee "scrollamount=10, width=200, behavior=slide" Mystr lenCOPY
不用过于拘泥于上面的参数格式(上面的调用格式仅是我的做法),我主要看有没有更好的方式以及精简的代码

(大家还可以将三个效果用三个函数分别实现)

特效  523066680兄的强项

TOP

本帖最后由 523066680 于 2011-5-8 23:44 编辑

函数的
调用的时候发送一个数字保持一直在增加的那种……
如果改成函数自己每次平移一下,函数中加个变量作记录也可以。
第三行那个没动作,没细看,没做。
@echo off
setlocal enabledelayedexpansion
set spec=bbs.bathome.net
call :countlength
for /l %%a in (1,1,100) do (set "s100= !s100!")
for /l %%a in (1,1,100) do (
for /l %%A in (1,1,300) do (echo >nul)
cls
call :run %spec% %%a 20
call :LR %spec% %%a 20
)
pause
:: $str $move $range
:run
set /a move=%2 %% (%3+len)
set result=!s100:~0,%3!%1%s100%
set result=!result:~%move%,%3!
echo,%result%
goto :eof
:LR
set /a spacerange=%3-len,move=spacerange - ( %2 %% (spacerange*2) +1)
set move=%move:-=%
set result=!s100:~0,%move%!%1
echo %result%
goto :eof
:countlength
set str=%1
for /l %%a in (1,1,1000) do (
if "!spec:~%%a!"=="" (
set /a len=%%a &&goto :eof
)
)COPY
1

评分人数

[url=][/url]

TOP

刚才笔误了,不是退格符,是制表符,也就是tab

TOP

歌词:“一切也只是曾经”
恩,不过跟效果有关的,比较多路数。帖子一出总有机会看到新颖的思路。
[url=][/url]

TOP

本帖最后由 zm900612 于 2011-5-9 12:55 编辑

不是很擅长特效,也没怎么思考过其中的技巧,所以写得比较复杂
@echo off
set /a 耗时=10,宽=40
set /p call=1、scroll  2、alternate  3、slide(Current) ^
   Your Choice:[.]
if "%call%"=="1" call:marquee "scrollamount=%耗时% width=%宽%  behavior=scroll" "bbs.bathome.net"
if "%call%"=="2" call:marquee "scrollamount=%耗时% width=%宽%  behavior=alternate" "bbs.bathome.net"
call:marquee "scrollamount=%耗时% width=%宽%  behavior=slide" "bbs.bathome.net"
:marquee
setlocal enabledelayedexpansion
title %*
for /f "skip=4 tokens=2" %%a in ('mode con') do if not defined cols set cols=%%a
for /f "tokens=1-3" %%a in (%1) do set %%c&set /a %%a,%%b
if %behavior%==slide set sl=::
set "$=%~2#"
set len=&for %%a in (128 64 32 16 8 4 2 1)do if !$:~%%a^,1!. NEQ . set/a len+=%%a&set $=!$:~%%a!
set th=【此处替换为制表符tab】
for /l %%a in (0 %cols% %width%) do echo;&set th=!th!
set "sr=%~2"
for /l %%a in (1 1 %width%) do set "sr= !sr!"
set k=!sr:~0,%width%!&set xh=!sr:~-%width%!
(if not %behavior%==alternate for /l %%a in (1 1 %len%) do (
echo !th! !k:~0,-%%a!!xh:~-%len%,%%a!
for /l %%b in (-%scrollamount%00 5) do cd.
)) 2>nul
if %behavior% neq scroll set /a "width-=len"
%sl% (set /a width-=1
%sl% for /l %%a in (1 %behavior:slide=%1 1) do (
for /l %%b in (1 1 %width%) do (
echo !th! !xh:~%%b!!xh:~0,%%b!
for /l %%b in (-%scrollamount%00 5) do cd.
)
%sl% if !behavior! neq scroll for /l %%b in (!width! -1) do (
%sl% echo !th! !xh:~%%b!!xh:~0,%%b!
%sl% for /l %%b in (-%scrollamount%00 5) do cd.)
%sl%)) 2>nul
endlocal
pause>nulCOPY
修改了下,代码更飘逸,思路更严谨
1

评分人数

TOP

返回列表