本帖最后由 CrLf 于 2015-12-26 05:16 编辑
改进自:http://www.bathome.net/redirect. ... id=38720&pid=179971
优化算法,提升效率,平衡取值,并加上了详细注释
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
....................................................................................................................................................................................................
代码和详解: | @echo off & setlocal enabledelayedexpansion | | | | rem 此处变量用于设置彩虹的各项参数 | | | | set /a n1=400,n2=250 | | | | | | | | set /a Lines=350 | | | | | | set /a stepCol=4,stepRow=17 | | | | | | | | rem 关键代码从这里开始 | | | | if !stepCol! lss !stepRow! ( | | set /a stepTest=stepCol | | ) else ( | | set /a stepTest=stepRow | | ) | | | | | | | | set "Count=0" | | | | | | for /l %%b in (0 %stepTest% %n1%) do ( | | | | | | set /a r1=%%b*%%b-n1*n1 | | | | | | if !r1! leq 0 ( | | | | | | set /a r2=%%b*%%b-n2*n2 | | | | | | if !Count!==0 set /a rMin=r[0]=!r2! | | | | | | if !r2! geq 0 ( | | | | | | set /a Count+=1,rMax=r2 | | | | | | for %%z in (!Count!) do set "r[%%z]=!r2!" | | | | ) | | ) | | ) | | | | for /l %%a in (1 1 7) do set /a "p%%a=Count-(7-%%a)*Count/7" | | | | | | for /l %%z in (0 1 !Count!) do ( | | | | | | set /a R=G=B=0 | | | | | | if %%z lss !p2! set /a "R=255-255*(%%z)/(p2)" | | if %%z geq !p3! if %%z lss !p4! set /a "R=(255*(%%z-p3)/(p4-p3))" | | if %%z geq !p4! set /a "R=255" | | | | | | | | | | | | if %%z lss !p2! set /a "G=255*(%%z)/(p2)" | | if %%z geq !p2! if %%z lss !p4! set /a "G=255" | | if %%z geq !p4! if %%z lss !p7! set /a "G=255-255*(%%z-p4)/(p7-p4)" | | | | | | | | | | | | if %%z lss !p2! set /a "B=255" | | if %%z geq !p2! if %%z lss !p3! set /a "B=255-255*(%%z-p2)/(p3-p2)" | | | | | | | | | | set /a RGB=R*256*256+G*256+B | | | | | | cmd /c "exit /b %%RGB%%" | | set "RGB[%%z]=#!=ExitCode:~-6!" | | | | ) | | | | set /a StartRow=stepCol/2-n1 | | set /a StartCol=stepRow/2 | | | | | | | | set /a EndRow=Lines-n1 | | set /a EndCol=n1-stepCol/2 | | | | | | | | (for /l %%a in (%StartRow% %stepRow% %EndRow%) do ( | | | | | | set "ubb=" | | | | | | for /l %%b in (%StartCol% %stepCol% %EndCol%) do ( | | | | | | set "fontcolor=white" | | | | | | set /a r2=%%a*%%a+%%b*%%b-n2*n2 | | | | | | if !r2! geq !rMin! if !r2! leq !rMax! ( | | | | | | for /l %%z in (0 1 !Count!) do ( | | if !r[%%z]! leq !r2! set "fontcolor=!RGB[%%z]!" | | | | ) | | ) | | | | set "ubb=[color=!fontcolor!].[/font]!ubb![color=!fontcolor!].[/font]" | | | | ) | | | | echo;!ubb! | | | | )) >ubb.txt | | | | start ubb.txt | | COPY |
|