批处理勾股画圆
发帖时就勾股定理还是股沟定理的问题纠结了半天,天呐,数学老师我对不起您...基本代码如下:[code]@echo off & setlocal EnableDelayedExpansion
set /a n=20
for /l %%a in (-%n% 2 %n%) do (
for /l %%b in (-%n% 1 %n%) do (
set /a r2=%%a*%%a+%%b*%%b-n*n
if !r2! gtr 0 (set /p=@) else set /p=_
)
echo;
)<nul
pause>nul[/code]以下没什么技术含量,纯凑字数显得帖子比较丰满。
稍稍改动画个空心圆:[code]
@echo off & setlocal EnableDelayedExpansion
set /a n=20,m=0,nn=n+1
for /l %%a in (-%n% 2 %n%) do (
setlocal
for /l %%b in (-%n% 1 %nn%) do (
set /a "m=(%%a*%%a+%%b*%%b-n*n-1)>>31",test=!m!-m
if !test!==1 (set r=!r!@) else (
if !test!==-1 (set "r=!r:~,-1!@ ") else set "r=!r! "
)
)
echo;!r!
endlocal
)
pause[/code]再简单加个循环...噢,我真蛋疼[code]@echo off & setlocal EnableDelayedExpansion
mode con:cols=220 lines=80
:c
set /a n+=1,m=0,nn=n+1
setlocal
for /l %%a in (-%n% 2 %n%) do (
for /l %%b in (-%n% 1 %nn%) do (
set /a "m=(%%a*%%a+%%b*%%b-n*n-1)>>31",test=!m!-m
if !test!==1 (set r%%a=!r%%a!@) else (
if !test!==-1 (set "r%%a=!r%%a:~,-1!@ ") else set "r%%a=!r%%a! "
)
)
set m=0
)
cls
for /l %%a in (-%n% 2 %n%) do echo !r%%a!
ping /n 1 localhost>nul
endlocal
goto c[/code]有兴趣的童鞋还可以尝试绘制同心圆 原来已经到达这种程度了啊,zm sama!
我对你的敬仰犹如滔滔江水……,你懂的 多圆并集:[code]@echo off & setlocal EnableDelayedExpansion
title 多圆并集
mode con:cols=102 lines=42
set /a x=50,y=40
for /l %%a in (-%y% 2 %y%) do (
set "echo= "
for /l %%b in (-%x% 1 %x%) do (
set "echo=!echo! "
for %%c in ("-42 -3 9" "-15 -26 7" "4 -15 6" "6 1 5" "17 16 4" "32 1 3" "45 4 2") do (
for /f "tokens=1-3" %%d in ("%%~c") do (
set /a "r2=(%%b-%%d)*(%%b-%%d)+(%%a-%%e)*(%%a-%%e)"-%%f*%%f*4"
if !r2! leq 0 set echo=!echo:~,-1!@
)
)
)
echo;!echo:~1!
)
pause>nul[/code]以此为基础的多个随机圆并集:[code]@echo off & setlocal EnableDelayedExpansion
title 随机圆
mode con:cols=102 lines=42
set /a x=50,y=40
for %%a in (2 3 4 5 6 7 9) do (
set /a a=!random!%%90-45,b=!random!%%60-30
set c=!c! "!a! !b! %%a"
)
for /l %%a in (-%y% 2 %y%) do (
set "echo= "
for /l %%b in (-%x% 1 %x%) do (
set "echo=!echo! "
for %%c in (!c!) do (
for /f "tokens=1-3" %%d in ("%%~c") do (
set /a "r2=(%%b-%%d)*(%%b-%%d)+(%%a-%%e)*(%%a-%%e)"-%%f*%%f*4"
if !r2! leq 0 set echo=!echo:~,-1!@
)
)
)
echo;!echo:~1!
)
pause>nul[/code] 空心圆实现起来有点麻烦,效率比较低,这里画一个奥运五环:[code]@echo off&setlocal EnableDelayedExpansion
(for /f "delims==" %%a in ('set') do set %%a=
path %path%)
set /a y=30,x=49
title 奥运五环
mode con:cols=100 lines=32
for /l %%a in (-%y% 2 %y%) do (
set /a echo=m1=m2=0
for /l %%b in (-%x% 1 %x%) do (
set "echo=!echo! "
for %%c in ("-26 -13 9" "0 -13 9" "26 -12 9" "-13 12 9" "13 12 9") do (
for /f "tokens=1-3" %%d in ("%%~c") do (
set /a "test=(((%%b-%%d)*(%%b-%%d)+(%%a-%%e)*(%%a-%%e)-%%f*%%f*4)>>31)-(((%%b-%%d+1)*(%%b-%%d+1)+(%%a-%%e)*(%%a-%%e)-%%f*%%f*4)>>31)","test/=test*test"&&set "echo=!echo:~,-1!@"
)
)
)
echo;!echo:~1!
) 2>nul
pause>nul
[/code] 我的天,这样都行…… 不过很占cpu下~ 实在是牛逼啊。。。。。。。。 [b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=93958&ptid=14276]1#[/url] [i]CrLf[/i] [/b]
长了见识。
以前开过贴子征集思路的,大家都只想到用开根的方法,没想到用勾股数。 真的是超乎想象,批处理还可以这样模拟画图动作,厉害了,大神 厉害了,大神 666 23333333333333333333
页:
[1]