chcp 437
if "%1"=="" (
for %%a in ( FontSize:00080008
FontFamily:00000030
WindowSize:003d0050
ScreenColors:0000000f
CodePage:000001b5
ScreenBufferSize:003d0050
) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do (
>nul reg add HKCU\Console\DosBatch_3D_Engine /v %%b /t reg_dword /d 0x%%c /f
)
start "DosBatch_3D_Engine" /max "%ComSpec%" /c "%~s0" 1&goto:eof
) else ( >nul reg delete HKCU\Console\DosBatch_3D_Engine /f )
@echo off & setlocal & title Sphere 3D & set /a cols=100, lines=70 & goto :Init_system
:Main
set /a ar=100, rt=0, ds=0, cx=cols/2, cz=4000, cY=lines/2
(
set SIN=
set _PLOT$_=
set _$PLOT_=
set _empty=
set lines=
set cols=
for /L %%\ in (1000,-1,0) do (
set /a "rt+=31416/60"
if !ds! lss 1000 set /a ds+=10
setlocal
set /a "a=(15708-rt) %% 62832, c=(a>>31|1)*a"
if !c! gtr 47124 (set /a "a=a-(a>>31|1)*62832, b=%SIN%, a=rt %% 62832, c=(a>>31|1)*a") else (if !c! gtr 15708 (set /a "a=(a>>31|1)*31416-a, b=%SIN%, a=rt %% 62832, c=(a>>31|1)*a") else set /a "b=%SIN%, a=rt %% 62832, c=(a>>31|1)*a")
if !c! gtr 47124 (set /a "a=a-(a>>31|1)*62832, a=%SIN%") else (if !c! gtr 15708 (set /a "a=(a>>31|1)*31416-a, a=%SIN%") else set /a "a=%SIN%")
for %%f in ("0 9999" "-5000 8661" "-8661 5000" "-9999 0" "-8661 -5000" "-5000 -8661" "0 -9999" "5000 -8661" "8661 -5000" "9999 0" "8661 5000" "5000 8661") do for /f "tokens=1,2" %%g in (%%f) do (
for %%t in ("3827 9239" "7071 7071" "9239 3827" "9999 0" "9239 -3827" "7071 -7071" "3827 -9239") do for /f "tokens=1,2" %%u in (%%t) do (
set /a "ax=ar*%%h/10000*%%u/10000, az=ar*%%g/10000*%%u/10000, ay=ar*%%v/10000, aax=(ax*b/10000-(ay*a/10000+az*b/10000)*a/10000)*b/10000-(ay*b/10000-az*a/10000)*a/10000, aay=(ax*b/10000-(ay*a/10000+az*b/10000)*a/10000)*a/10000+(ay*b/10000-az*a/10000)*b/10000, e=ax*a/10000+(ay*a/10000+az*b/10000)*b/10000, c=ds*aax/(e-cz)+cx, d=ds*aay/(e-cz)+cy"
if not defined L!d! set L!d!=%_empty%
if !e! lss 0 (%_$PLOT_% !c! !d! 1 %_PLOT$_%) else %_$PLOT_% !c! !d! 4 %_PLOT$_%
)
)
if not "!OT!"=="!time:~-1!" (
cls & (For /L %%l in (1,1,%lines%) do if not defined L%%l (echo() else echo( !L%%l!)>CON
if "!OT!"=="0" title Sphere 3D [%%\]
endlocal
set OT=!time:~-1!
) else endlocal
)
)
goto :eof
:Init_system
setlocal DisableDelayedExpansion
set /a cc=cols+2, ll=lines+2
(
mode %cc%,%ll% & cls
for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="
set /a cols=%cols%, lines=%lines%
)
set "_$PLOT_=For /F usebackq^ tokens^=1-3 %%x in ('"
set "_PLOT$_=') do set /a f=%%x+1 & For %%w in (!f!) do set L%%y=!L%%y:~0,%%x!!g:~%%z,1!!L%%y:~%%w!"
set "SIN=(a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000)"
setlocal EnableDelayedExpansion
color 0a
For /L %%l in (1,1,%cols%) do set "_empty=!_empty! "
set g= .±2@"
Goto :Main
第二款,可以通过按键控制,请看提示。
[Bash shell] 纯文本查看复制代码
@echo off
setlocal EnableDelayedExpansion
REM APA mod
if "%1" neq "" goto %1
title Sphere 3D
:: By einstein1969. Dedicated to jeb, dbenham, penpen, carlos, aGerman, Aacini, EdDyreen,
:: npocmaka_, Sponge Belly, Magialisk, the users and the staff of Dostips forum.
:: Use raster font 8x8
:: v 0.0.2 passed from 16.6 FPS to ~20.0 FPS
:: Variables enigma:
:: ? = Sphere radius
:: rt = Rotation angle
:: ds = Distance Z of sphere
:: _dx,_dy = Offset x,y of projecting coordinates in 2D plane.
:: a,b = Sine, cosine of rotation angle
:: ax,ay,az = Rotation coordinate 3D, now a, b, c
:: c,d = X,Y coordinate of projecting 3D to 2D, now a,b
:: e = Z coordinate, now c
REM Interactive version by Antonio Perez Ayala aka Aacini
cls
echo/
echo Sphere 3D original version by einstein1969
echo Interactive version by Aacini
echo/
echo Sphere 3D rotation is controlled by WASDERQZ keys this way:
echo/
echo zoom in up
echo \ ^| counterclockwise ^<- E R -^> clockwise
echo Q W
echo left ^<- A S D -^> right
echo Z ^|
echo / down
echo zoom out
echo/
echo/
echo -^> Press P key to pause/exit
echo/
pause
:Init_system
set /a cols=62, lines=58
set /a cc=cols+2, ll=lines+2
mode %cc%,%ll% & cls
(
for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="
set /a cols=%cols%, lines=%lines%
REM APA mod
set "ComSpec=%ComSpec%"
)
set "_SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
REM APA mod: Convert final sine calculation into a long "function" expression
REM [url]http://www.dostips.com/forum/viewtopic.php?f=3&t=6744[/url]
REM if !c! gtr 47124 (set /a "a=a-(a>>31|1)*62832") else if !c! gtr 15708 set /a "a=(a>>31|1)*31416-a"
set "SIN(x)=(a=(x)%%62832, c=(a>>31|1)*a, t=((c-47125)>>31)+1, a-=t*((a>>31|1)*62832) + ^^^!t*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), %_SIN%)"
set "_SIN="
For /L %%l in (1,1,%cols%) do set "_empty=!_empty! "
REM APA mod
set "g=.ABCDEFGNS"
REM APA mod
set /a ?=100, rx=0, ry=0, rz=0, ds=800, _dx=cols/2, _dy=lines/2, _dz=4000, _1=10000
REM APA mod: Start the control and animation processes in parallel
cd . > pipeFile.txt
"%~F0" Input >> pipeFile.txt | "%~F0" Main < pipeFile.txt
del pipeFile.txt
goto :EOF
REM APA mod: Control part: get control keys and send the corresponding command to the animation part
:Input
set /A Drx=0, Dry=0, Drz=0, Dr=31416/180
set "letter= ADWSERQZP"
set "com[A]=Dry-=Dr,ry-=1" & set "var[A]=Dry"
set "com[D]=Dry+=Dr,ry+=1" & set "var[D]=Dry"
set "com[W]=Drz-=Dr,rz+=1" & set "var[W]=Drz"
set "com[S]=Drz+=Dr,rz-=1" & set "var[S]=Drz"
set "com[E]=Drx-=Dr,rx-=1" & set "var[E]=Drx"
set "com[R]=Drx+=Dr,rx+=1" & set "var[R]=Drx"
set "com[Q]=ds+=100" & set "var[Q]=ds"
set "com[Z]=ds-=100" & set "var[Z]=ds"
set "com[P]=ps=1" & set "var[P]=ps"
:getKey
title Sphere 3D: rx=%ry%, ry=%rz%, rz=%rx%, zoom=%ds:~0,-1%%%
C:\Windows\System32\choice /C %letter% /N
set "option=!letter:~%errorlevel%,1!"
set /A "!com[%option%]!"
set "var=!var[%option%]!"
echo %var%=!%var%!
if %option% neq P goto getKey
C:\Windows\System32\choice /C CSX /N
if %errorlevel% neq 3 (
if %errorlevel% equ 1 (
echo Continue
) else (
set /A Drx=Dry=Drz=rx=ry=rz=0
echo Stop
)
goto getKey
)
echo Exit
C:\Windows\System32\ping localhost -n 3 > NUL
exit
:pause
set "ps=0"
set /P "=Press C to Continue, S to Stop movement or X to eXit: " < NUL
:wait
set /P "command="
if "%command%" equ "Exit" exit
if "%command%" equ "Stop" set /A Drx=Dry=Drz=0 & exit /B
if "%command%" neq "Continue" goto wait
exit /B
:Main
(setlocal
for /F "Tokens=1 delims==" %%v in ('set _') do set "%%v="
set "lines="
set "cols="
REM APA mod
set "ComSpec="
rem giro completo (120)*31416/60 o multipli di 120
for /L %%\ in () do (
REM APA mod: Get control command and execute it
set /P "command="
if defined command (
set /A "!command!"
set "command="
if "!ps!" equ "1" call :pause
)
REM APA Instead of: if !ds! lss 1000 (set /a ds+=10) else %_FPS%
set /a "rx+=Drx, ry+=Dry, rz+=Drz"
setlocal
REM APA mod: Calculate sine and cosine of rotating angles in three axis
set /A "sx=%SIN(x):x=rx%"
set /A "cx=%SIN(x):x=15708-rx%"
set /A "sy=%SIN(x):x=ry%"
set /A "cy=%SIN(x):x=15708-ry%"
set /A "sz=%SIN(x):x=rz%"
set /A "cz=%SIN(x):x=15708-rz%"
REM APA mod %%a %%b %%c %%d %%e %%f
For /f "tokens=1-6" %%a in ("!sx! !cx! !sy! !cy! !sz! !cz!") do (
REM APA mod: Calculate rotation common factors *much* less times (just once!)
set /A "p=%%a*%%f/10000, q=%%a*%%e/10000, r=%%b*%%f/10000, s=%%b*%%e/10000, t=%%b*%%c/10000, u=%%a*%%c/10000"
REM APA "sin cos" of 12 angles in %%i %%j for Sphere meridians (x axis)
for %%h in ("0 9999" "-5000 8661" "-8661 5000" "-9999 0" "-8661 -5000" "-5000 -8661" "0 -9999" "5000 -8661" "8661 -5000" "9999 0" "8661 5000" "5000 8661") do for /f "tokens=1,2" %%i in (%%h) do (
REM APA "sin cos" of 7 angles in %%u %%v for Sphere parallels (y axis)
set "i=0"
for %%t in ("3827 9239" "7071 7071" "9239 3827" "9999 0" "9239 -3827" "7071 -7071" "3827 -9239") do for /f "tokens=1,2" %%u in (%%t) do (
REM APA Calculate a sphere point
set /A "a=?*%%j/10000*%%u/10000, b=?*%%v/10000, c=?*%%i/10000*%%u/10000"
REM APA MOD!: Rotation on all axis
set /A "x=(a*%%b-b*%%a)/10000*%%d/10000 - c*%%c/10000, v=c*%%d/10000"
set /A "y=a*(p - t *%%e/10000)/10000 + b*(r + u *%%e/10000)/10000 - v *%%e/10000"
set /A "z=a*(q + t *%%f/10000)/10000 + b*(s - u *%%f/10000)/10000 + v *%%f/10000"
REM APA Projection of 3D to 2D
set /A "a=ds*x/(z-%_dz%)+%_dx%, b=ds*y/(z-%_dz%)+%_dy%, APA=(i+=1)*((z>>31)+1)"
if not defined L!b! set "L!b!=%_empty%"
REM APA mod: _$PLOT_ ... _PLOT$_ code inserted here
For /F "tokens=1-3" %%x in ("!a! !b! !APA!") do (
set "c=!L%%y:~%%x!"
REM APA mod: Give preference to "top" points over "bottom" ones
if "%%z" neq "0" (
set "L%%y=!L%%y:~0,%%x!!g:~%%z,1!!c:~1!"
) else if "!c:~0,1!" equ " " (
set "L%%y=!L%%y:~0,%%x!.!c:~1!"
)
)
)
)
REM APA mod: Draw the North and South Poles
for %%v in (1 -1) do (
set /A "b=?*%%v, x=(-b*%%a)/10000*%%d/10000, y=b*(r+u*%%e/10000)/10000, z=b*(s-u*%%f/10000)/10000"
set /A "a=ds*x/(z-%_dz%)+%_dx%, b=ds*y/(z-%_dz%)+%_dy%, APA=(i+=1)*((z>>31)+1)"
if not defined L!b! set "L!b!=%_empty%"
For /F "tokens=1-3" %%x in ("!a! !b! !APA!") do (
set "c=!L%%y:~%%x!"
if "%%z" neq "0" (set "L%%y=!L%%y:~0,%%x!!g:~%%z,1!!c:~1!") else if "!c:~0,1!" equ " " set "L%%y=!L%%y:~0,%%x!.!c:~1!"
)
)
)
cls & For /L %%l in (1,1,%lines%) do echo/ !L%%l!
endlocal
)
endlocal)