Skip to content

Commit 26c7a4a

Browse files
Update 3D_rotating_pyramid.bat
1 parent 3fe4ff3 commit 26c7a4a

File tree

1 file changed

+90
-5
lines changed

1 file changed

+90
-5
lines changed

3D_rotating_pyramid/3D_rotating_pyramid.bat

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mode %wid%,%hei%
66
call :macros
77

88
set /a top.x=wid / 2, top.y=20, pyramid.hei=33, pyramid.wid=19
9-
for /l %%i in (0,1,3) do set /a "angle=90 * %%i",^
9+
for /l %%i in (0,1,3) do set /a "angle=QUARTER_PI * 2 * %%i",^
1010
"cx[%%i]=pyramid.wid * !cos:x=angle!/10000 + top.x",^
1111
"cy[%%i]=(pyramid.wid / 2 - pyramid.wid / 4) * !sin:x=angle!/10000 + top.y + pyramid.hei"
1212

@@ -18,9 +18,9 @@ for /l %%# in (1,1,1000) do (
1818
title %%#
1919
if !dt! gtr 5 (
2020

21-
set /a "t1=t2","frames+=6"
21+
set /a "t1=t2","frames+=(pi >> 5)"
2222

23-
for /l %%i in (0,1,3) do ( set /a "angle=(90 * %%i + frames)",^
23+
for /l %%i in (0,1,3) do ( set /a "angle=(QUARTER_PI * 2 * %%i + frames)",^
2424
"cx[%%i]=pyramid.wid * !cos:x=angle!/10000 + top.x",^
2525
"cy[%%i]=(pyramid.wid / 2 - pyramid.wid / 4) * !sin:x=angle!/10000 + top.y + pyramid.hei",^
2626
"next=(%%i + 1) %% 4"
@@ -43,8 +43,93 @@ rem ----------------------------------------------------------------------------
4343
)
4444
for /f %%a in ('echo prompt $E^| cmd') do set "\e=%%a"
4545

46-
set "sin=(a=((x*31416/180)%%62832)+(((x*31416/180)%%62832)>>31&62832), b=(a-15708^a-47124)>>31,a=(-a&b)+(a&~b)+(31416&b)+(-62832&(47123-a>>31)),a-a*a/1875*a/320000+a*a/1875*a/15625*a/16000*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000)"
47-
set "cos=(a=((15708-x*31416/180)%%62832)+(((15708-x*31416/180)%%62832)>>31&62832), b=(a-15708^a-47124)>>31,a=(-a&b)+(a&~b)+(31416&b)+(-62832&(47123-a>>31)),a-a*a/1875*a/320000+a*a/1875*a/15625*a/16000*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000)"
46+
set /a "PI=31416, HALF_PI=PI / 2, TAU=TWO_PI=2*PI, PI32=PI+HALF_PI, QUARTER_PI=PI / 4"
47+
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"
48+
set "sin=(a=( x)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832) + (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), !_SIN!)"
49+
set "cos=(a=(15708 - x)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832) + (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), !_SIN!)"
50+
set "_sin="
51+
52+
rem %@AAline% x0 x1 y0 y1 <rtn> !$AAline!
53+
set @AAline=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-4" %%1 in ("^!args^!") do (%\n%
54+
set "$AAline="%\n%
55+
set /a "$dx=(((%%~3-%%~1)>>31|1)*(%%~3-%%~1))","$dy=(((%%~4-%%~2)>>31|1)*(%%~4-%%~2))", "$x0=%%~1,$y0=%%~2,$x1=%%~3,$y1=%%~4", "$err=$dx-$dy", "dxdy=$dx+$dy","dist=$dx"%\n%
56+
if ^^!$dx^^! lss ^^!$dy^^! ( set /a "dist=$dy" )%\n%
57+
if %%~1 lss %%~3 ( set $sx=1 ) else ( set $sx=-1 )%\n%
58+
if %%~2 lss %%~4 ( set $sy=1 ) else ( set $sy=-1 )%\n%
59+
if ^^!dxdy^^! equ 0 ( set $ed=1 ) else ( set /a "$ed=dist" )%\n%
60+
for /l %%i in (1,1,^^!dist^^!) do (%\n%
61+
set /a "$shade=255 - (255 * ((($err-$dx+$dy)>>31|1)*($err-$dx+$dy)) / $ed)", "e2=$err, x2=$x0", "$2e2=2 * e2", "color=232 + (255 - 232) * $shade / 255"%\n%
62+
set "$AAline=^!$AAline^!%\e%[48;5;^!color^!m%\e%[^!$y0^!;^!$x0^!H "%\n%
63+
if ^^!$2e2^^! geq -^^!$dx^^! (%\n%
64+
set /a "e2dy=e2 + $dy"%\n%
65+
if ^^!e2dy^^! lss ^^!$ed^^! if ^^!$x0^^! neq ^^!$x1^^! (%\n%
66+
set /a "$shade=255 - (255 * (((e2+$dy)>>31|1)*(e2+$dy)) / $ed)", "$y0sy=$y0 + $sy", "color=232 + (255 - 232) * $shade / 255"%\n%
67+
set "$AAline=^!$AAline^!%\e%[48;5;^!color^!m%\e%[^!$y0sy^!;^!$x0^!H "%\n%
68+
)%\n%
69+
set /a "$err-=$dy, $x0+=$sx"%\n%
70+
)%\n%
71+
if ^^!$2e2^^! leq ^^!$dy^^! if ^^!$y0^^! neq ^^!$y1^^! (%\n%
72+
set /a "dxe2=$dx - e2"%\n%
73+
if ^^!dxe2^^! lss ^^!$ed^^! (%\n%
74+
set /a "$shade=255 - (255 * ((($dx-e2)>>31|1)*($dx-e2)) / $ed)", "x2sx=x2 + $sx", "color=232 + (255 - 232) * $shade / 255"%\n%
75+
set "$AAline=^!$AAline^!%\e%[48;5;^!color^!m%\e%[^!$y0^!;^!x2sx^!H "%\n%
76+
)%\n%
77+
set /a "$err+=$dx, $y0+=$sy"%\n%
78+
)%\n%
79+
)%\n%
80+
set "$AAline=^!$AAline^!%\e%[0m"%\n%
81+
)) else set args=
82+
goto :eof
83+
@echo off & setlocal enableDelayedExpansion
84+
85+
set /a "wid=100,hei=70"
86+
mode %wid%,%hei%
87+
88+
call :macros
89+
90+
set /a top.x=wid / 2, top.y=20, pyramid.hei=33, pyramid.wid=19
91+
for /l %%i in (0,1,3) do set /a "angle=QUARTER_PI * 2 * %%i",^
92+
"cx[%%i]=pyramid.wid * !cos:x=angle!/10000 + top.x",^
93+
"cy[%%i]=(pyramid.wid / 2 - pyramid.wid / 4) * !sin:x=angle!/10000 + top.y + pyramid.hei"
94+
95+
for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "t1=((((10%%a-1000)*60+(10%%b-1000))*60+(10%%c-1000))*100)+(10%%d-1000)"
96+
for /l %%# in (1,1,1000) do (
97+
98+
for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "t2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, dt=t2-t1"
99+
100+
title %%#
101+
if !dt! gtr 5 (
102+
103+
set /a "t1=t2","frames+=(pi >> 5)"
104+
105+
for /l %%i in (0,1,3) do ( set /a "angle=(QUARTER_PI * 2 * %%i + frames)",^
106+
"cx[%%i]=pyramid.wid * !cos:x=angle!/10000 + top.x",^
107+
"cy[%%i]=(pyramid.wid / 2 - pyramid.wid / 4) * !sin:x=angle!/10000 + top.y + pyramid.hei",^
108+
"next=(%%i + 1) %% 4"
109+
110+
%@aaline% !top.x! !top.y! !cx[%%i]! !cy[%%i]!
111+
set "scrn=!scrn!%\e%[!cy[%%i]!;!cx[%%i]!H!$aaline!"
112+
113+
for %%n in (!next!) do %@aaline% !cx[%%i]! !cy[%%i]! !cx[%%n]! !cy[%%n]!
114+
set "scrn=!scrn!%\e%[!cy[%%i]!;!cx[%%i]!H!$aaline!"
115+
)
116+
117+
echo=%\e%[2J%\e%[H!scrn!
118+
set "scrn="
119+
)
120+
)
121+
rem ------------------------------------------------------------------------------------------------------------------------------------
122+
:macros
123+
(set \n=^^^
124+
%= This creates an escaped Line Feed - DO NOT ALTER \n =%
125+
)
126+
for /f %%a in ('echo prompt $E^| cmd') do set "\e=%%a"
127+
128+
set /a "PI=31416, HALF_PI=PI / 2, TAU=TWO_PI=2*PI, PI32=PI+HALF_PI, QUARTER_PI=PI / 4"
129+
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"
130+
set "sin=(a=( x)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832) + (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), !_SIN!)"
131+
set "cos=(a=(15708 - x)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832) + (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), !_SIN!)"
132+
set "_sin="
48133

49134
rem %@AAline% x0 x1 y0 y1 <rtn> !$AAline!
50135
set @AAline=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-4" %%1 in ("^!args^!") do (%\n%

0 commit comments

Comments
 (0)