Hack Forums
[Shell] Rotating 3D cube pure batch - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Rotating 3D cube pure batch (/showthread.php?tid=5835165)



Rotating 3D cube pure batch - ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ - May 10, 2018

[Image: bac5c29fcb7c7524212124384d9e8927.gif]

Code
@echo off & setlocal enableDelayedExpansion

if /i "%controller%" equ "enabled" if "%~1" neq "" goto :%~1

REM INITIALIZE -----------------------------------------------------------------------------
call :macros

mode 100,100
set "controller=enabled"
set "controls=WSADZX"



REM CHANGE ME
2>nul set /a "sides=%~1" || set /a "sides=4"
REM -------------

set /a "size=18"
set /a "x=50", "y=50"
set /a "angle=360 / sides"
set /a "rotationSpeed=10"
set /a "depth=10"
set /a "P_ANGLE=0"

rem Û
REM ----------------------------------------------------------------------------------------
if /i "%controller%" equ "enabled" (
    if exist "%temp%\%~n0_signal.txt" del "%temp%\%~n0_signal.txt"
    "%~F0" Controller %controls% >"%temp%\%~n0_signal.txt" | "%~F0" GAME_ENGINE <"%temp%\%~n0_signal.txt"
)
:GAME_ENGINE
    for /l %%# in () do (        set /a "frame+=1"
    
        rem User Controller
            if /i "%controller%" equ "enabled" set "com=" & set /p "com="
            
                   if /i "!com!" equ "D" ( set /a "rotationSpeed+=5"
            ) else if /i "!com!" equ "A" ( set /a "rotationSpeed-=5"
            ) else if /i "!com!" equ "W" ( if !depth! lss 25 set /a "depth+=2", "x-=1", "y-=1"
            ) else if /i "!com!" equ "S" ( if !depth! gtr 5 set /a "depth-=2", "x+=1", "y+=1"
            ) else if /i "!com!" equ "Z" ( if !size! gtr 10 set /a "size-=3"
            ) else if /i "!com!" equ "X"   if !size! lss 24 set /a "size+=3"

            set /a "angle0+=rotationSpeed"
            
            for %%i in (1 2) do ( for /l %%c in (1,1,%sides%) do (
                    set /a "b=%%c - 1" & for %%b in (!b!) do set /a "angle%%c=!angle%%b! + angle"
                    set /a "xoff=x", "yoff=y"
                    if %%i equ 1 (
                        set /a "x%%i_%%c=size * !cos(x):x=angle%%c! + xoff"
                        set /a "y%%i_%%c=size * !sin(x):x=angle%%c! + yoff"
                    ) else (
                        set /a "x%%i_%%c=size * !cos(x):x=angle%%c! + (xoff + depth)"
                        set /a "y%%i_%%c=size * !sin(x):x=angle%%c! + (yoff + depth)"
                    )
                )
                set /a "c=sides + 1" & set /a "x%%i_!c!=x%%i_1", "y%%i_!c!=y%%i_1"
            )
            
            for %%i in (1 2) do for /l %%c in (1,1,%sides%) do (
                set /a "d=%%c + 1"
                for %%b in (!d!) do (
                    %line% !x%%i_%%c! !y%%i_%%c! !x%%i_%%b! !y%%i_%%b! %%c
                    set /a "connect_%%i_%%b_X=!x%%i_%%c!"
                    set /a "connect_%%i_%%b_Y=!y%%i_%%c!"
                )
            )
            
            for /l %%c in (1,1,%sides%) do ( set /a "d=%%c + 1"
                for %%b in (!d!) do (
                    %line% !connect_1_%%b_X! !connect_1_%%b_Y! !connect_2_%%b_X! !connect_2_%%b_Y! %%c
                )
            )
        
        
        rem display everything using VT100 2J sequence to clear the screen first.
        set "stats1=%esc%[9;5HA - Decrease rotation speed       Z - Zoom out     W - Increase Depth"
        set "stats2=%esc%[11;5HD - Increase rotation speed       X - Zoom in      S - Decrease depth"
        set "stats3=%esc%[13;5H Rotation Speed = !rotationSpeed!%esc%[14;5H Zoom - !size!"
        set "stats4=%esc%[5;5HSides = !sides!;  Point at every !angle! Degrees;  Depth = !depth!"
        set "statsBuffer=!stats1!!stats2!!stats3!!stats4!"
        <nul set /p "=%esc%[2J!screen!!statsBuffer!"
        set "screen="
    )
exit

:Controller
    if /i "%controller%" equ "enabled" (
        for /l %%# in () do for /f "tokens=*" %%a in ('choice /c:%~2 /n') do <nul set /p ".=%%a"
    )



    
    
    
    
    
    
    
    
    
    
    
    
    
    


:macros
set ^"LF=^

^" Above empty line is required - do not remove
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
<nul set /p "=!esc![?25l"

rem %plot% x y 0-255 CHAR
set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-4" %%1 in ("^!args^!") do (%\n%
  set "screen=^!screen^!!esc![%%2;%%1H!esc![38;5;%%3m%%~4!esc![0m"%\n%
)) else set args=

rem line x1 y1 x2 y2 color
set line=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
    if "%%~5" equ "" ( set "hue=30" ) else ( set "hue=%%~5")%\n%
    set /a "xa=%%~1", "ya=%%~2", "xb=%%~3", "yb=%%~4", "dx=%%~3 - %%~1", "dy=%%~4 - %%~2"%\n%
    for /f "tokens=1-2" %%6 in ("^!dx^! ^!dy^!") do (%\n%
        if %%~7 lss 0 ( set /a "dy=-%%~7", "stepy=-1" ) else ( set "stepy=1" )%\n%
        if %%~6 lss 0 ( set /a "dx=-%%~6", "stepx=-1" ) else ( set "stepx=1" )%\n%
        set /a "dx<<=1", "dy<<=1"%\n%
    )%\n%
    for /f "tokens=1-9" %%a in ("^!dx^! ^!dy^! ^!xa^! ^!xb^! ^!ya^! ^!yb^! ^!stepx^! ^!stepy^! ^!hue^!") do (%\n%
        if %%~a gtr %%~b (%\n%
            set /a "fraction=%%~b - (%%~a >> 1)"%\n%
            for /l %%x in (%%~c,%%~g,%%~d) do (%\n%
                for /f "tokens=1" %%6 in ("^!fraction^!") do if %%~6 geq 0 set /a "ya+=%%~h", "fraction-=%%~a"%\n%
                set /a "fraction+=%%~b"%\n%
                for /f "tokens=1" %%6 in ("^!ya^!") do (%\n%
                    if 0 leq %%x if %%x lss 199 if 0 leq %%~6 if %%~6 lss 199 ^!plot^! %%x %%~6 %%i Û%\n%
                )%\n%
            )%\n%
        ) else (%\n%
            set /a "fraction=%%~a - (%%~b >> 1)"%\n%
            for /l %%y in (%%~e,%%~h,%%~f) do (%\n%
                for /f "tokens=1" %%6 in ("^!fraction^!") do if %%~6 geq 0 set /a "xa+=%%~g", "fraction-=%%~b"%\n%
                set /a "fraction+=%%~a"%\n%
                for /f "tokens=1" %%6 in ("^!xa^!") do (%\n%
                    if 0 leq %%~6 if %%~6 lss 199 if 0 leq %%y if %%y lss 199 ^!plot^! %%~6 %%y %%i Û%\n%
                )%\n%
            )%\n%
        )%\n%
    )%\n%
)) else set args=

    set /a "PI=(35500000/113+5)/10, PI_div_2=(35500000/113/2+5)/10, PIx2=2*PI, PI32=PI+PI_div_2"
    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"
    set "SIN(x)=(a=(x * 31416 / 180)%%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%) / 10000"
    set "COS(x)=(a=(15708 - x * 31416 / 180)%%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%) / 10000"
    set "_SIN="
    set "Abs(x)=(((x)>>31|1)*(x))"
goto :eof



RE: Rotating 3D cube pure batch - Phlox - May 10, 2018

3D cube wow fantastic work mate!

What is wrong with gif you have posted shell i see if i can create a better gif for you?


RE: Rotating 3D cube pure batch - pms - May 11, 2018

Was looking forward to see the results on this one and man, this is amazing.


RE: Rotating 3D cube pure batch - Karakum - May 13, 2018

Awesome! Now I'm your fan. We believe that this world is real!


RE: Rotating 3D cube pure batch - Sir-Teabag - May 13, 2018

That's so cool dude! Keep up the great work

You should try to do an animation of a firework or something.. if you haven't already lol


RE: Rotating 3D cube pure batch - ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ - May 13, 2018

(May 13, 2018 06:29 PM)Sir-Teabag Wrote:  That's so cool dude! Keep up the great work

You should try to do an animation of a firework or something.. if you haven't already lol

Funny you should mention

https://hackforums.net/showthread.php?tid=5826799


RE: Rotating 3D cube pure batch - Erhan - May 27, 2018

Another stunning batch script from you, thanks!!