Advertisement
IcarusLives

Batch Animation COMMENTED

Aug 8th, 2017
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.60 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2.  
  3. REM :canvas is "foundation" for game dev/art design & patterns/drawing in batch. Givings a "map" with a boarder to move around. + more features.
  4. call:canvas 50 50 # "title"
  5.  
  6. REM Define Math functions
  7.     set /a "PI=(35500000/113+5)/10, PI_div_2=(35500000/113/2+5)/10, PIx2=2*PI, PI32=PI+PI_div_2"
  8.     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"
  9.     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"
  10.     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"
  11.     set "_SIN="
  12.  
  13. for %%a in ("p1x=22" "p2x=20" "p3x=18" "p4x=16" "p5x=14" "p1y=14" "p2y=14" "p3y=14"
  14.             "p4y=14" "p5y=14" "p6x=12" "p6y=14" "p7x=10" "p7y=14") do set %%~a
  15.  
  16.  
  17. REM Infinite loop
  18. for /l %%# in (0 0 0) do ( set /a "angle+=1"
  19.        
  20.     set /a "p1x=20 * !cos(x):x=7 * angle! * !sin(x):x=angle! + width/2"
  21.     set /a "p1y=20 * !cos(x):x=7 * angle! * !cos(x):x=angle! + height/2"
  22.        
  23.     set /a "next_p2x=p1x", "next_p2y=p1y", "next_p3x=p2x", "next_p3y=p2y", "next_p4x=p3x", "next_p4y=p3y", "next_p5x=p4x", "next_p5y=p4y", "next_p6x=p5x", "next_p6y=p5y", "next_p7x=p6x", "next_p7y=p6y"
  24.     set /a "p7x=p6x", "p7y=p6y", "p6x=p5x", "p6y=p5y", "p5x=p4x", "p5y=p4y", "p4x=p3x", "p4y=p3y","p3x=p2x", "p3y=p2y", "p2x=p1x", "p2y=p1y"
  25.        
  26.     REM Draw our circles, and ^%plot^% the tail
  27.     %circle% p1x p1y 1 *
  28.     %circle% width/2 height/2 3 o /f
  29.     for /l %%a in (2,1,7) do ( %plot% next_p%%ax next_p%%ay * )
  30.        
  31.     REM Display the screen
  32.     call :showCanvas
  33.     call :updateCanvas
  34. )
  35. exit
  36.  
  37. REM --- END ENGINE ---
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. REM --- FUNCTIONS ---
  50.  
  51. :canvas
  52. set ^"LF=^
  53.  
  54. ^" Above empty line is required - do not remove
  55. set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
  56.         call:macros
  57.         call:cursorpos 2>nul
  58.         if "%~2" neq "" ( set /a "width=%~1 - 1", "height=%~2 - 1" ) else ( goto :eof )
  59.         if "%~3" neq "" ( set "canvasChar=%~3" ) else ( set "canvasChar=#" )
  60.         if "%~4" neq "" ( set "title=%~4" ) else ( set "title=CANVAS" )
  61.         if "%~7" neq "" ( if /i "%~5" equ "/c" (
  62.                 set "CAM=/c"
  63.                 set /a "CAM_Y=0", "CAM_X=0", "maxX=%~6", "winMaxY=%~7","cols=maxX + 5", "rows=winMaxY + 8"
  64.                 if not defined outerBuffer ( for /l %%a in (-1,1,!maxX!) do (
  65.                     set "outerBuffer=!outerBuffer!%canvasChar%") )
  66.                 if !maxX!    geq %width%  set /a "maxX=width"
  67.                 if !winMaxY! geq %height% set /a "winMaxY=height"
  68.             )
  69.         ) else (
  70.             set /a "cols=width + 5", "rows=height + 8"
  71.             if not defined outerBuffer ( for /l %%a in (-2,1,%width%) do (
  72.                 set "outerBuffer=!outerBuffer!%canvasChar%") )
  73.         )
  74.         if not defined Controller ( set "Controller=set "com="^^& set /p "com="" )
  75.         if not defined multithread_dispatcher ( set "multithread_dispatcher=if "%%~1" neq "" call :%%~1 "%%~2"" )
  76.         for /l %%a in (0,1,%width%)  do set "widthBuffer=!widthBuffer! "
  77.         call:updateCanvas
  78.         if exist "%temp%\cursorpos.exe" (
  79.             set "cls="%temp%\cursorpos.exe" 0 1" ) else ( set "cls=cls" )
  80.         mode con: cols=%cols% lines=%rows%
  81.         title %title%
  82.     goto :eof
  83.  
  84.     :updateCanvas
  85.         if "%~2" neq "" ( if /i "%~1" equ "/f" ( if exist "%tmp%\Canvas_%~2.txt" (
  86.                     set "_=-1"
  87.                     for /f "tokens=*" %%a in (%tmp%\Canvas_%~2.txt) do (
  88.                         set /a "_+=1" & set "tmp_%~2_[!_!]=%%~a"
  89.                         call set "expanded_=%%tmp_%~2_[!_!]%%"
  90.                         if "!expanded_:~0,2!" equ "::" call:canvas !expanded_:~3!
  91.                     )
  92.                     call:updateCanvas /v %~2
  93.                 )
  94.             ) else if /i "%~1" equ "/v" ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=!tmp_%~2_[%%a]!" ) )
  95.         ) else ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=%widthBuffer%" ) )
  96.     goto :eof
  97.  
  98.     :showCanvas
  99.         %cls%
  100.         echo= %outerBuffer%
  101.         if /i "%CAM%" neq "/c" (
  102.             for /l %%a in (0,1,%height%) do ( echo= %canvasChar:~0,1%!_[%%a]!%canvasChar:~0,1%)
  103.         ) else if "%~3" neq "" (
  104.             set /a "maxY=CAM_Y + winMaxY", "_line=%~1 + 1" & if !maxY! gtr %height% set /a "maxY=height"
  105.             for /l %%a in (!CAM_Y!,1,!maxY!) do (
  106.                 set "line=!_[%%a]!"
  107.                 if "%%a" equ "%~2" for /f "tokens=1-3" %%a in ("%~1 %~3 !_line!") do set "line=!line:~0,%%a!%%b!line:~%%c!"
  108.                 echo= !canvasChar:~0,1!!line:~%CAM_X%,%maxX%!!canvasChar:~0,1!
  109.             )
  110.         ) else echo Missing Parameters
  111.         echo= %outerBuffer%
  112.     goto :eof
  113. goto :eof
  114.  
  115.  
  116. :macros
  117. :: Canvas Macros -------------------------------------------------------------------
  118. :: %PLOT%
  119. set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-3" %%1 in ("^!args^!") do (%\n%
  120.     set /a "_y=%%2", "_x=%%1", "_x2=%%1 + 1"%\n%
  121.     for /f "tokens=1-4" %%a in ("_y ^!_y^! ^!_x^! ^!_x2^!") do set "_[^!%%a^!]=^!_[%%b]:~0,%%c^!%%3^!_[%%b]:~%%d^!"%\n%
  122. )) else set args=
  123.  
  124. :: %circle%
  125. set circle=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
  126.         for /l %%y in (-%%3,1,%%3) do for /l %%x in (-%%3,1,%%3) do (%\n%
  127.             set /a "S=(%%x * %%x) + (%%y * %%y) - (%%3 * %%3)", "_3div2=%%3 / 2"%\n%
  128.             for /f "tokens=1,2" %%a in ("^!S^! ^!_3div2^!") do (%\n%
  129.                        if "%%5" equ "/f" ( if %%a leq 1    ^!plot^! %%x+%%1 %%y+%%2 %%4 %\n%
  130.                 ) else if "%%5" equ "/n" ( if %%a geq -%%3 ^!plot^! %%x+%%1 %%y+%%2 %%4 %\n%
  131.                 ) else if %%a geq -%%3 if %%a leq %%b      ^!plot^! %%x+%%1 %%y+%%2 %%4 %\n%
  132.         ))%\n%
  133.         set "s="%\n%
  134. )) else set args=
  135.  
  136. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement