Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- REM :canvas is "foundation" for game dev/art design & patterns/drawing in batch. Givings a "map" with a boarder to move around. + more features.
- call:canvas 50 50 # "title"
- REM Define Math functions
- 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="
- for %%a in ("p1x=22" "p2x=20" "p3x=18" "p4x=16" "p5x=14" "p1y=14" "p2y=14" "p3y=14"
- "p4y=14" "p5y=14" "p6x=12" "p6y=14" "p7x=10" "p7y=14") do set %%~a
- REM Infinite loop
- for /l %%# in (0 0 0) do ( set /a "angle+=1"
- set /a "p1x=20 * !cos(x):x=7 * angle! * !sin(x):x=angle! + width/2"
- set /a "p1y=20 * !cos(x):x=7 * angle! * !cos(x):x=angle! + height/2"
- 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"
- 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"
- REM Draw our circles, and ^%plot^% the tail
- %circle% p1x p1y 1 *
- %circle% width/2 height/2 3 o /f
- for /l %%a in (2,1,7) do ( %plot% next_p%%ax next_p%%ay * )
- REM Display the screen
- call :showCanvas
- call :updateCanvas
- )
- exit
- REM --- END ENGINE ---
- REM --- FUNCTIONS ---
- :canvas
- set ^"LF=^
- ^" Above empty line is required - do not remove
- set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
- call:macros
- call:cursorpos 2>nul
- if "%~2" neq "" ( set /a "width=%~1 - 1", "height=%~2 - 1" ) else ( goto :eof )
- if "%~3" neq "" ( set "canvasChar=%~3" ) else ( set "canvasChar=#" )
- if "%~4" neq "" ( set "title=%~4" ) else ( set "title=CANVAS" )
- if "%~7" neq "" ( if /i "%~5" equ "/c" (
- set "CAM=/c"
- set /a "CAM_Y=0", "CAM_X=0", "maxX=%~6", "winMaxY=%~7","cols=maxX + 5", "rows=winMaxY + 8"
- if not defined outerBuffer ( for /l %%a in (-1,1,!maxX!) do (
- set "outerBuffer=!outerBuffer!%canvasChar%") )
- if !maxX! geq %width% set /a "maxX=width"
- if !winMaxY! geq %height% set /a "winMaxY=height"
- )
- ) else (
- set /a "cols=width + 5", "rows=height + 8"
- if not defined outerBuffer ( for /l %%a in (-2,1,%width%) do (
- set "outerBuffer=!outerBuffer!%canvasChar%") )
- )
- if not defined Controller ( set "Controller=set "com="^^& set /p "com="" )
- if not defined multithread_dispatcher ( set "multithread_dispatcher=if "%%~1" neq "" call :%%~1 "%%~2"" )
- for /l %%a in (0,1,%width%) do set "widthBuffer=!widthBuffer! "
- call:updateCanvas
- if exist "%temp%\cursorpos.exe" (
- set "cls="%temp%\cursorpos.exe" 0 1" ) else ( set "cls=cls" )
- mode con: cols=%cols% lines=%rows%
- title %title%
- goto :eof
- :updateCanvas
- if "%~2" neq "" ( if /i "%~1" equ "/f" ( if exist "%tmp%\Canvas_%~2.txt" (
- set "_=-1"
- for /f "tokens=*" %%a in (%tmp%\Canvas_%~2.txt) do (
- set /a "_+=1" & set "tmp_%~2_[!_!]=%%~a"
- call set "expanded_=%%tmp_%~2_[!_!]%%"
- if "!expanded_:~0,2!" equ "::" call:canvas !expanded_:~3!
- )
- call:updateCanvas /v %~2
- )
- ) else if /i "%~1" equ "/v" ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=!tmp_%~2_[%%a]!" ) )
- ) else ( for /l %%a in (0,1,%height%) do ( set "_[%%a]=%widthBuffer%" ) )
- goto :eof
- :showCanvas
- %cls%
- echo= %outerBuffer%
- if /i "%CAM%" neq "/c" (
- for /l %%a in (0,1,%height%) do ( echo= %canvasChar:~0,1%!_[%%a]!%canvasChar:~0,1%)
- ) else if "%~3" neq "" (
- set /a "maxY=CAM_Y + winMaxY", "_line=%~1 + 1" & if !maxY! gtr %height% set /a "maxY=height"
- for /l %%a in (!CAM_Y!,1,!maxY!) do (
- set "line=!_[%%a]!"
- if "%%a" equ "%~2" for /f "tokens=1-3" %%a in ("%~1 %~3 !_line!") do set "line=!line:~0,%%a!%%b!line:~%%c!"
- echo= !canvasChar:~0,1!!line:~%CAM_X%,%maxX%!!canvasChar:~0,1!
- )
- ) else echo Missing Parameters
- echo= %outerBuffer%
- goto :eof
- goto :eof
- :macros
- :: Canvas Macros -------------------------------------------------------------------
- :: %PLOT%
- set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-3" %%1 in ("^!args^!") do (%\n%
- set /a "_y=%%2", "_x=%%1", "_x2=%%1 + 1"%\n%
- for /f "tokens=1-4" %%a in ("_y ^!_y^! ^!_x^! ^!_x2^!") do set "_[^!%%a^!]=^!_[%%b]:~0,%%c^!%%3^!_[%%b]:~%%d^!"%\n%
- )) else set args=
- :: %circle%
- set circle=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
- for /l %%y in (-%%3,1,%%3) do for /l %%x in (-%%3,1,%%3) do (%\n%
- set /a "S=(%%x * %%x) + (%%y * %%y) - (%%3 * %%3)", "_3div2=%%3 / 2"%\n%
- for /f "tokens=1,2" %%a in ("^!S^! ^!_3div2^!") do (%\n%
- if "%%5" equ "/f" ( if %%a leq 1 ^!plot^! %%x+%%1 %%y+%%2 %%4 %\n%
- ) else if "%%5" equ "/n" ( if %%a geq -%%3 ^!plot^! %%x+%%1 %%y+%%2 %%4 %\n%
- ) else if %%a geq -%%3 if %%a leq %%b ^!plot^! %%x+%%1 %%y+%%2 %%4 %\n%
- ))%\n%
- set "s="%\n%
- )) else set args=
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement