Lots of useful batch functions
Page 1 of 1
Lots of useful batch functions
Hello all, just dropping a list of functions that I find to be very useful ALL THE TIME in batch development. Hopefully you all find them useful too.
:mouse (yes clicking)
::---------------------------------------------------------------------------------------
:: cMouse will create MOUSE.exe if not already exist in %temp%
::
:: @echo off & setlocal enableDelayedExpansion
:: call :cMouse
::
:: :main
:: cls
:: call :mouse
:: echo C = %c%
:: echo X = %x%
:: echo Y = %y%
:: goto :main
::
::
::---------------------------------------------------------------------------------------
:cMouse
if not exist "%temp%\mouse.exe" (
for %%a in ("TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v"
"dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAATAECAAAAAAAAAAAA"
"AAAAAOAADwMLAQYAAAAAAAAAAAAAAAAAQBEAAAAQAAAAIAAAAABAAAAQAAAAAgAA"
"BAAAAAAAAAAEAAAAAAAAAFAhAAAAAgAAAAAAAAMAAAAAABAAABAAAAAAEAAAEAAA"
"AAAAABAAAAAAAAAAAAAAACAgAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAABcIAAALAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC50ZXh0AAAA"
"ABAAAAAQAAAAAgAAAAIAAAAAAAAAAAAAAAAAACAAAGAuZGF0YQAAAFABAAAAIAAA"
"UgEAAAAEAAAAAAAAAAAAAAAAAABAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVieWB7AgAAACQjUX6UOgs"
"AAAAg8QED79F/lAPv0X8UA+2RfpQuA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ZQAAAFNldENvbnNvbGVNb2RlAAAAUmVh"
"ZENvbnNvbGVJbnB1dEEAAAAA") do (
echo %%~a>>cMouse.txt
)
certutil -decode cMouse.txt %temp%\mouse.exe
del /f /q cmouse.txt
)
goto :eof
:mouse
for %%a in (c x y) do set "%%a="
for /f "tokens=1-3" %%W in ('"%temp%\Mouse.exe"') do set /a "c=%%W,x=%%X,y=%%Y"
goto :eof
NOTE: :write requires :length function
:canvas, :showCanvas, :updateCanvas
:: Function package: canvas, showCanvas, updateCanvas
:: returns = _[0-n], width, height
::
:: Parameters are returned as width and height
::
:: call :canvas 50 50
:: I would like a canvas of 50 LINES that are 50 COLUMNS long
::
:: call :canvasDisplay
:: pause
::
:: width = 50 height 30
::
:: call :canvas %width% %height%
::
::---------------------------------------------------------------------------------------
:canvas
@echo off
set /a "width=%~1 - 1", "height=%~2 - 1", "_=-1", "conWidth=width + 4", "conHeight=height + 5"
if exist cursorpos.exe ( set "cls=cursorpos 0 0" ) else ( set "cls=cls" )
for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
for /l %%a in (1,1,%width%) do set "widthBuffer=!widthBuffer! "
call :updateCanvas
mode con: cols=%conWidth% lines=%conHeight%
goto :eof
:updateCanvas
for /l %%a in (1,1,%height%) do set /a "_+=1" & set "_[!_!]=%widthBuffer%"
set "_="
goto :eof
:showCanvas
%cls%
echo=%outerBuffer%
for /l %%a in (1,1,%height%) do echo=#!_[%%a]!#
echo=%outerBuffer%
goto :eof
goto :eof
:plot x y
::--------------------------------------------------------------------------------------
::
:: REQUIRES: :canvas, :canvasDisplay
::
:: Can place a point on X,Y created by :canvas
::
:: call :canvas
::
:: set x=10
:: set y=15
::
:: call :plot %x% %y%
::
:: call :canvasDisplay
::--------------------------------------------------------------------------------------
:plot x y
setlocal
set /a "_x2=%~1 + 1"
(endlocal
set "_[%~2]=!_[%~2]:~0,%~1!.!_[%~2]:~%_x2%!"
if "%~3" neq "" set "plot[%~1,%~2]="
)
goto :eof
:plotLine x0 y0 x1 y1
:: -------------------------------------------------------------------------------------------
:: :plotLine x0 y0 x1 y1 requires :canvas, :showCanvas, :plot
::
:: call :canvas 30 30
::
:: call :plotLine 14 6 24 23
::
:: call :showCanvas
::
:: -------------------------------------------------------------------------------------------
:plotLine x0 y0 x1 y1
set /a "x0=%~1", "y0=%~2", "x1=%~3", "y1=%~4", "dx=x1 - x0", "dy=y1 - y0"
if %dy% lss 0 ( set /a "dy=-dy", "stepy=-1" ) else ( set /a "stepy=1")
if %dx% lss 0 ( set /a "dx=-dx", "stepx=-1" ) else ( set /a "stepx=1")
set /a "dx<<=1", "dy<<=1"
if %dx% gtr %dy% (
set /a "fraction=dy - (dx >> 1)"
for /l %%x in (%x0%,%stepx%,%x1%) do (
if !fraction! geq 0 (
set /a "y0+=stepy"
set /a "fraction-=dx"
)
set /a "fraction+=dy"
if 0 leq %%x if %%x lss %width% if 0 leq !y0! if !y0! lss %width% (
call :plot %%x !y0!
)
)
) else (
set /a "fraction=dx - (dy >> 1)"
for /l %%y in (%y0%,%stepy%,%y1%) do (
if !fraction! geq 0 (
set /a "x0+=stepx"
set /a "fraction-=dy"
)
set /a "fraction+=dx"
if 0 leq !x0! if !x0! lss %width% if 0 leq %%y if %%y lss %width% (
call :plot !x0! %%y
)
)
)
for %%a in (x0 y0 x1 y1 dx dy stepx stepy fraction) do set "%%a="
goto :eof
:swap VAR1 VAR2
:: --------------------------------------------------------------------------------------
:: :swap x y swap values of VAR1 and VAR2
::
:: set /a "x=14", "y=27"
::
:: echo X = %x% Y = %y%
::
:: call :swap x y
::
:: echo X = %x% Y = %y%
::
:: --------------------------------------------------------------------------------------
:swap
setlocal
set "temp=!%~1!"
(endlocal
set "%~1=!%~2!"
set "%~2=%temp%"
)
goto :eof
:ellipse x y r
:: ------------------------------------------------------------------------------------------------------
::
:: REQUIRES :canvas, :plot, :showCanvas
::
:: draws a circle on x,y with a radius of r
::
:: call :ellipse x y r
::
:: call :canvas 40 40
::
:: call :ellipse 7 7 3
::
:: call :showCanvas
::
:: ------------------------------------------------------------------------------------------------------
:ellipse x y r
for /l %%y in (-%~3,1,%~3) do for /l %%x in (-%~3,1,%~3) do (
set /a "S=(%%x * %%x) + (%%y * %%y) - (%~3 * %~3) - 1", "t=-%~3 - 1"
if !S! geq !t! if !S! leq 1 ( set /a "x=%%x + %~1", "y=%%y + %~2" & call :plot !x! !y! )
)
goto :eof
:rect x y h w
Spoiler (Click to Hide)
:: -------------------------------------------------------------------------------------------------------
:: :rect x y h w requires :canvas, :showCanvas, :plot, :plotLine
::
:: call :canvas 30 30
::
:: call :rect 14 6 3 5
::
:: call :showCanvas
::
:: -------------------------------------------------------------------------------------------------------
:rect x y h w
set /a "rect_x=%~1", "rect_y=%~2", "rect_h=%~2 + %~4", "rect_w=%~1 + %~3"
call :plotLine %rect_x% %rect_y% %rect_w% %rect_y%
call :plotLine %rect_x% %rect_y% %rect_x% %rect_h%
call :plotLine %rect_w% %rect_h% %rect_w% %rect_y%
call :plotLine %rect_w% %rect_h% %rect_x% %rect_h%
for %%a in (rect_h rect_w rect_x rect_y) do set "%%a="
goto :eof
:emptyVarEnviornment
:: Parameters are names of variables that you do NOT want to be cleared.
::
:: call :emptyVarEnviornment var1 var2
::
:: var1 and var2 will be preserved
::---------------------------------------------------------------------------------------
:emptyVarEnviornment
set "preserve= preserve path %~1 "
for /f "delims==" %%v in ('set') do if "!preserve: %%v =!" equ "!preserve!" set "%%v="
set "preserve="
goto :eof
:hexPrint
Spoiler (Click to Hide)
:: Get special characters
::
:: call :hexPrint 0x03 heart
:: call :hexPrint 0x04 diamond
:: call :hexPrint 0x05 club
:: call :hexPrint 0x06 spade
::
:: first parameter is hex for character you want
:: second parameter is name of variable it is given to
::
::---------------------------------------------------------------------------------------
:hexPrint string [rtnVar]
for /f delims^=^ eol^= %%A in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
goto :eof
:color
Spoiler (Click to Hide)
::---------------------------------------------------------------------------------------
:: Color text on screen
::
:: call :color 5D "Hello World" 1
:: call :color EC "Hello World" 0
:: call :color 9A "Hello World" 0
::
::---------------------------------------------------------------------------------------
:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 <nul set /p ".=">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
if %3 == 1 echo >%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
:prep_CalcFPS, :calcFPS
::---------------------------------------------------------------------------------------
:: FPS CALC and FPS Delay
::
:: @echo off & setlocal enableDelayedExpansion
:: call :prep_calcFPS 1-99
::
:: :main
::
:: call :calcFPS
:: goto :main
::
::
::---------------------------------------------------------------------------------------
:prep_calcFPS
set /A cs=100/%~1
set t=!time: =0!
goto :eof
:calcFPS
(
set tc=!time: =0!
for /F "tokens=1-8 delims=:.," %%a in ("!t!:!tc!") do (
set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"
)
if !a! lss !cs! goto :calcFPS
if !a! gtr !cs! set /a a-=1
set t=!tc!
if !a! neq 0 (set /A fps=100/a) else set fps=?
title FPS:!fps!/s
)
goto :eof
:delay
::---------------------------------------------------------------------------------------
:: Delay NUMBER(1-n)
::
:: More useful than timeout or ping
::
::
:: instead, use
:: call :delay 10
::
:: will delay for 10ms
::
::---------------------------------------------------------------------------------------
:delay
for /f "tokens=2 delims=." %%a in ("%time%") do (set "c=%%a")
if "%c:~0,1%" == "0" set "c=%c:~1%"
set /a l=%c% + %~1
:wait
set "cPrev=%c%"
for /f "tokens=2 delims=." %%a in ("%time%") do (set "c=%%a")
if "%c:~0,1%" == "0" set "c=%c:~1%"
if %cPrev% GTR %c% set /a l-=100
if %c% LSS %l% goto :wait
goto :eof
:length
::---------------------------------------------------------------------------------------
:: Get the length of a string or number
::
:: call :length "Hello World" varName
:: echo %varName%
::---------------------------------------------------------------------------------------
:length
setlocal
set "str=X%~1"
set length=0
for /L %%a in (8,-1,0) do (
set /a "length|=1<<%%a"
for %%b in (!length!) do if "!str:~%%b,1!" equ "" set /a "length&=~1<<%%a"
)
(endlocal
if "%~2" neq "" ( set "%2=%length%" ) else echo %length%
)
goto :eof
:pow
::---------------------------------------------------------------------------------------
:: square a number
::
:: call :pow 12 2 RETURNVAR
:: echo %RETURNVAR%
::---------------------------------------------------------------------------------------
:pow
setlocal
set "out=1"
for /l %%a in (1,1,%2) do set /a "out*=%1"
if %~1 equ 0 set "out=1"
(endlocal
if "%~3" neq "" ( set "%~3=%out%" ) else echo %out%
)
goto :eof
:factorial
::---------------------------------------------------------------------------------------
:: Get the factorial of a number
::
:: call :factorial 7 RETURNVAR
:: echo %RETURNVAR%
::---------------------------------------------------------------------------------------
:factorial
setlocal
set "out=1"
for /l %%a in (%~1,-1,1) do set /a "out*=%%a"
if %~1 equ 0 set "out=1"
(endlocal
if "%~2" neq "" ( set "%~2=%out%" ) else echo %out%
)
goto :eof
:sqrt
::--------------------------------------------------------------------------------------------------
:: Square root a number
::
:: call :sqrt 144
:: call :sqrt 144 return_var
::
::--------------------------------------------------------------------------------------------------
:sqrt
setlocal
set "s=%~1"
set /A "x=s/(11*1024)+40,x=(s/x+x)>>1,x=(s/x+x)>>1,x=(s/x+x)>>1,x=(s/x+x)>>1,x=(s/x+x)>>1,x+=(s-x*x)>>31
(endlocal
if "%~2" neq "" ( set %~2=%x% ) else echo %x%
)
goto :eof
:specialCharacters
Spoiler (Click to Hide)
Code:
:Neg_Or_Pos
:: call :Neg_or_Pos NUMBER [/p, /n, /r] outVAR
::
:: /p - records NUMBER to outVAR IF NUMBER is Positive
:: /n - records NUMBER to outVAR IF NUMBER is Negative
:: /r - records NUMBER to outVAR regardless
::
:: outVAR = any name you want, but must not contain variables.
:Neg_or_Pos
set "NoP_p2=%~2"
echo %1|findstr /c:"-" >nul 2>&1
if "!NoP_p2!" equ "" (
if !errorlevel! equ 1 echo %1 = Positive
if !errorlevel! equ 0 echo %1 = Negative
goto :eof
) else if not "!NoP_p2!" equ "" (
if /i "!NoP_p2:~1,1!" equ "p" if !errorlevel! equ 1 set "%~3=%1"
if /i "!NoP_p2:~1,1!" equ "n" if !errorlevel! equ 0 set "%~3=%1"
if /i "!NoP_p2:~1,1!" equ "r" set "%~3=%1"
)
set "NoP_p2="
:Grid
:: call :grid /A-Z NUMBER "boxHeightxboxWidth" /s
::
:: /A-Z is rows, allowing up to 26. Meaning you can have 26 boxes long.
::
:: NUMBER = Number of boxes tall
::
:: "boxHeightxboxWidth" = Height and Width of individual boxes
::
:: /s = OPTIONAL will display overlay data of grid.
::
::
:: call :grid /E 3 "5x9" /s
:grid
set "_t=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
set "gHeight=%2" & set "z=%1" & set "z=!z:~1,1!"
for %%a in (%_t%) do set /a "i+=1" & if /i "%%a" equ "%z%" set "gWidth=!i!"
for /f "tokens=1,2 delims=x" %%a in ("%~3") do set /a "bHeight=%%a + 1", "bWidth=%%b"
set /a "g=((gWidth * bWidth) + bWidth)", "gridMaxHeight=(gHeight * bHeight) + 1"
set /a "gridMaxWidth=g - bWidth + gWidth + 1", "_w=bWidth + 1"
for /l %%a in (1,1,%bWidth%) do set "s=!s! "
for /l %%a in (1,%bWidth%,%g%) do set "d=!d!!s!#"
for /l %%a in (1,1,%gridMaxHeight%) do set "line[%%a]=#!line[%%a]!!d:~0,-%bWidth%!"
for /l %%a in (1,1,%gridMaxWidth%) do set "line[0]=!line[0]!#"
for /l %%a in (1,%bHeight%,%gridMaxHeight%) do set "line[%%a]=!line[0]!"
if "%~4" equ "/s" set "ol=GRID: %gridMaxHeight%x%gridMaxWidth%/[A-%z%] x %gHeight%. - %~3 boxes"
:init_rainbow, :Rainbow_text
:: ---------------------------------------------------------------------------------------------------------------------------
:: Displays rainbow text up to 45 chars
::
:: call :init_rainbow
:: call :rainbow_text "TEXT
::
:: ---------------------------------------------------------------------------------------------------------------------------
:rainbow_text
set "str=x%~1" & <nul set /p ".=["
for %%a in (%rainbow_text%) do (
set /a "i+=1"
call set "ex_str=%%str:~!i!,1%%"
if "!ex_str!" equ "" ( <nul set /p ".=]" & echo. & goto :eof )
if "!ex_str!" equ " " (
<nul set /p ".=] ["
) else (
(> colorPrint.txt (echo [!ex_str!]\..\') && findstr /a:0%%a /f:colorPrint.txt ".")
)
)
:init_rainbow
set "rainbow_text=4 C 6 E 2 A 1 9 3 B 5 D F 7 8 0 4 C 6 E 2 A 1 9 3 B 5 D F 7 8 0 4 C 6 E 2 A 1 9 3 B 5 D F 7 8 0"
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E & echo on & for %%b in (1) do rem"') do set "DEL=%%a"
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" > "'"
goto :eof
CLICK ME :build_alphabet, :bigText
:: --------------------------------------------------------------------------------------------------------------------------------------------------------------------
:: :bigText displays color in desired from from :build_alphabet function (NOT COMPLETE)
::
:: call :bigText "Hello" 54 " " 1f "World" c3
:: --------------------------------------------------------------------------------------------------------------------------------------------------------------------
:bigText
setlocal
set "a=1"
:getArgs
if "%~1" neq "" set /a "args+=1" & set "t[!args!]=%~1"
if "%~2" neq "" set "c[!args!]=%~2"
shift & shift & if "%~1" neq "" ( goto :getArgs )
:getLetter
if defined t[%a%] (
set "e[%a%]=!t[%a%]:~%p%,1!" & set "cs=!e[%a%]!"
set /a "p+=1", "n[%a%]+=1"
set "cha[%a%][!n[%a%]!]=!cs!"
if "!cs!" equ "" set /a "a+=1", "p=0"
goto :getLetter
)
for /l %%c in (1,1,%b_a_btMAX%) do for /l %%a in (1,1,%args%) do for /l %%b in (1,1,!n[%%a]!) do call set "o[%%a][%%c]=!o[%%a][%%c]!%%_!cha[%%a][%%b]![%%c]%%"
for /l %%b in (1,1,%b_a_btMAX%) do ( for /l %%a in (1,1,%args%) do (>cp.txt ( echo=!o[%%a][%%b]!\..\') && findstr /a:!c[%%a]! /f:cp.txt ".") ) & echo.
endlocal
:mouse (yes clicking)
::---------------------------------------------------------------------------------------
:: cMouse will create MOUSE.exe if not already exist in %temp%
::
:: @echo off & setlocal enableDelayedExpansion
:: call :cMouse
::
:: :main
:: cls
:: call :mouse
:: echo C = %c%
:: echo X = %x%
:: echo Y = %y%
:: goto :main
::
::
::---------------------------------------------------------------------------------------
:cMouse
if not exist "%temp%\mouse.exe" (
for %%a in ("TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v"
"dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAATAECAAAAAAAAAAAA"
"AAAAAOAADwMLAQYAAAAAAAAAAAAAAAAAQBEAAAAQAAAAIAAAAABAAAAQAAAAAgAA"
"BAAAAAAAAAAEAAAAAAAAAFAhAAAAAgAAAAAAAAMAAAAAABAAABAAAAAAEAAAEAAA"
"AAAAABAAAAAAAAAAAAAAACAgAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAABcIAAALAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC50ZXh0AAAA"
"ABAAAAAQAAAAAgAAAAIAAAAAAAAAAAAAAAAAACAAAGAuZGF0YQAAAFABAAAAIAAA"
"UgEAAAAEAAAAAAAAAAAAAAAAAABAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVieWB7AgAAACQjUX6UOgs"
"AAAAg8QED79F/lAPv0X8UA+2RfpQuAAgQABQ6IgBAACDxBC4AAAAAOkAAAAAycNV"
"ieWB7CQAAACQuPb///9Q6GwBAACJRfy4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%~a>>cMouse.txt
)
certutil -decode cMouse.txt %temp%\mouse.exe
del /f /q cmouse.txt
)
goto :eof
:mouse
for %%a in (c x y) do set "%%a="
for /f "tokens=1-3" %%W in ('"%temp%\Mouse.exe"') do set /a "c=%%W,x=%%X,y=%%Y"
goto :eof
NOTE: :write requires :length function
:canvas, :showCanvas, :updateCanvas
:: Function package: canvas, showCanvas, updateCanvas
:: returns = _[0-n], width, height
::
:: Parameters are returned as width and height
::
:: call :canvas 50 50
:: I would like a canvas of 50 LINES that are 50 COLUMNS long
::
:: call :canvasDisplay
:: pause
::
:: width = 50 height 30
::
:: call :canvas %width% %height%
::
::---------------------------------------------------------------------------------------
:canvas
@echo off
set /a "width=%~1 - 1", "height=%~2 - 1", "_=-1", "conWidth=width + 4", "conHeight=height + 5"
if exist cursorpos.exe ( set "cls=cursorpos 0 0" ) else ( set "cls=cls" )
for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
for /l %%a in (1,1,%width%) do set "widthBuffer=!widthBuffer! "
call :updateCanvas
mode con: cols=%conWidth% lines=%conHeight%
goto :eof
:updateCanvas
for /l %%a in (1,1,%height%) do set /a "_+=1" & set "_[!_!]=%widthBuffer%"
set "_="
goto :eof
:showCanvas
%cls%
echo=%outerBuffer%
for /l %%a in (1,1,%height%) do echo=#!_[%%a]!#
echo=%outerBuffer%
goto :eof
goto :eof
:plot x y
::--------------------------------------------------------------------------------------
::
:: REQUIRES: :canvas, :canvasDisplay
::
:: Can place a point on X,Y created by :canvas
::
:: call :canvas
::
:: set x=10
:: set y=15
::
:: call :plot %x% %y%
::
:: call :canvasDisplay
::--------------------------------------------------------------------------------------
:plot x y
setlocal
set /a "_x2=%~1 + 1"
(endlocal
set "_[%~2]=!_[%~2]:~0,%~1!.!_[%~2]:~%_x2%!"
if "%~3" neq "" set "plot[%~1,%~2]="
)
goto :eof
:plotLine x0 y0 x1 y1
:: -------------------------------------------------------------------------------------------
:: :plotLine x0 y0 x1 y1 requires :canvas, :showCanvas, :plot
::
:: call :canvas 30 30
::
:: call :plotLine 14 6 24 23
::
:: call :showCanvas
::
:: -------------------------------------------------------------------------------------------
:plotLine x0 y0 x1 y1
set /a "x0=%~1", "y0=%~2", "x1=%~3", "y1=%~4", "dx=x1 - x0", "dy=y1 - y0"
if %dy% lss 0 ( set /a "dy=-dy", "stepy=-1" ) else ( set /a "stepy=1")
if %dx% lss 0 ( set /a "dx=-dx", "stepx=-1" ) else ( set /a "stepx=1")
set /a "dx<<=1", "dy<<=1"
if %dx% gtr %dy% (
set /a "fraction=dy - (dx >> 1)"
for /l %%x in (%x0%,%stepx%,%x1%) do (
if !fraction! geq 0 (
set /a "y0+=stepy"
set /a "fraction-=dx"
)
set /a "fraction+=dy"
if 0 leq %%x if %%x lss %width% if 0 leq !y0! if !y0! lss %width% (
call :plot %%x !y0!
)
)
) else (
set /a "fraction=dx - (dy >> 1)"
for /l %%y in (%y0%,%stepy%,%y1%) do (
if !fraction! geq 0 (
set /a "x0+=stepx"
set /a "fraction-=dy"
)
set /a "fraction+=dx"
if 0 leq !x0! if !x0! lss %width% if 0 leq %%y if %%y lss %width% (
call :plot !x0! %%y
)
)
)
for %%a in (x0 y0 x1 y1 dx dy stepx stepy fraction) do set "%%a="
goto :eof
:swap VAR1 VAR2
:: --------------------------------------------------------------------------------------
:: :swap x y swap values of VAR1 and VAR2
::
:: set /a "x=14", "y=27"
::
:: echo X = %x% Y = %y%
::
:: call :swap x y
::
:: echo X = %x% Y = %y%
::
:: --------------------------------------------------------------------------------------
:swap
setlocal
set "temp=!%~1!"
(endlocal
set "%~1=!%~2!"
set "%~2=%temp%"
)
goto :eof
:ellipse x y r
:: ------------------------------------------------------------------------------------------------------
::
:: REQUIRES :canvas, :plot, :showCanvas
::
:: draws a circle on x,y with a radius of r
::
:: call :ellipse x y r
::
:: call :canvas 40 40
::
:: call :ellipse 7 7 3
::
:: call :showCanvas
::
:: ------------------------------------------------------------------------------------------------------
:ellipse x y r
for /l %%y in (-%~3,1,%~3) do for /l %%x in (-%~3,1,%~3) do (
set /a "S=(%%x * %%x) + (%%y * %%y) - (%~3 * %~3) - 1", "t=-%~3 - 1"
if !S! geq !t! if !S! leq 1 ( set /a "x=%%x + %~1", "y=%%y + %~2" & call :plot !x! !y! )
)
goto :eof
:rect x y h w
Spoiler (Click to Hide)
:: -------------------------------------------------------------------------------------------------------
:: :rect x y h w requires :canvas, :showCanvas, :plot, :plotLine
::
:: call :canvas 30 30
::
:: call :rect 14 6 3 5
::
:: call :showCanvas
::
:: -------------------------------------------------------------------------------------------------------
:rect x y h w
set /a "rect_x=%~1", "rect_y=%~2", "rect_h=%~2 + %~4", "rect_w=%~1 + %~3"
call :plotLine %rect_x% %rect_y% %rect_w% %rect_y%
call :plotLine %rect_x% %rect_y% %rect_x% %rect_h%
call :plotLine %rect_w% %rect_h% %rect_w% %rect_y%
call :plotLine %rect_w% %rect_h% %rect_x% %rect_h%
for %%a in (rect_h rect_w rect_x rect_y) do set "%%a="
goto :eof
:emptyVarEnviornment
:: Parameters are names of variables that you do NOT want to be cleared.
::
:: call :emptyVarEnviornment var1 var2
::
:: var1 and var2 will be preserved
::---------------------------------------------------------------------------------------
:emptyVarEnviornment
set "preserve= preserve path %~1 "
for /f "delims==" %%v in ('set') do if "!preserve: %%v =!" equ "!preserve!" set "%%v="
set "preserve="
goto :eof
:hexPrint
Spoiler (Click to Hide)
:: Get special characters
::
:: call :hexPrint 0x03 heart
:: call :hexPrint 0x04 diamond
:: call :hexPrint 0x05 club
:: call :hexPrint 0x06 spade
::
:: first parameter is hex for character you want
:: second parameter is name of variable it is given to
::
::---------------------------------------------------------------------------------------
:hexPrint string [rtnVar]
for /f delims^=^ eol^= %%A in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
) do if "%~2" neq "" (set %~2=%%A) else echo(%%A
goto :eof
:color
Spoiler (Click to Hide)
::---------------------------------------------------------------------------------------
:: Color text on screen
::
:: call :color 5D "Hello World" 1
:: call :color EC "Hello World" 0
:: call :color 9A "Hello World" 0
::
::---------------------------------------------------------------------------------------
:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 <nul set /p ".=">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
if %3 == 1 echo >%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
:prep_CalcFPS, :calcFPS
::---------------------------------------------------------------------------------------
:: FPS CALC and FPS Delay
::
:: @echo off & setlocal enableDelayedExpansion
:: call :prep_calcFPS 1-99
::
:: :main
::
:: call :calcFPS
:: goto :main
::
::
::---------------------------------------------------------------------------------------
:prep_calcFPS
set /A cs=100/%~1
set t=!time: =0!
goto :eof
:calcFPS
(
set tc=!time: =0!
for /F "tokens=1-8 delims=:.," %%a in ("!t!:!tc!") do (
set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"
)
if !a! lss !cs! goto :calcFPS
if !a! gtr !cs! set /a a-=1
set t=!tc!
if !a! neq 0 (set /A fps=100/a) else set fps=?
title FPS:!fps!/s
)
goto :eof
:delay
::---------------------------------------------------------------------------------------
:: Delay NUMBER(1-n)
::
:: More useful than timeout or ping
::
::
:: instead, use
:: call :delay 10
::
:: will delay for 10ms
::
::---------------------------------------------------------------------------------------
:delay
for /f "tokens=2 delims=." %%a in ("%time%") do (set "c=%%a")
if "%c:~0,1%" == "0" set "c=%c:~1%"
set /a l=%c% + %~1
:wait
set "cPrev=%c%"
for /f "tokens=2 delims=." %%a in ("%time%") do (set "c=%%a")
if "%c:~0,1%" == "0" set "c=%c:~1%"
if %cPrev% GTR %c% set /a l-=100
if %c% LSS %l% goto :wait
goto :eof
:length
::---------------------------------------------------------------------------------------
:: Get the length of a string or number
::
:: call :length "Hello World" varName
:: echo %varName%
::---------------------------------------------------------------------------------------
:length
setlocal
set "str=X%~1"
set length=0
for /L %%a in (8,-1,0) do (
set /a "length|=1<<%%a"
for %%b in (!length!) do if "!str:~%%b,1!" equ "" set /a "length&=~1<<%%a"
)
(endlocal
if "%~2" neq "" ( set "%2=%length%" ) else echo %length%
)
goto :eof
:pow
::---------------------------------------------------------------------------------------
:: square a number
::
:: call :pow 12 2 RETURNVAR
:: echo %RETURNVAR%
::---------------------------------------------------------------------------------------
:pow
setlocal
set "out=1"
for /l %%a in (1,1,%2) do set /a "out*=%1"
if %~1 equ 0 set "out=1"
(endlocal
if "%~3" neq "" ( set "%~3=%out%" ) else echo %out%
)
goto :eof
:factorial
::---------------------------------------------------------------------------------------
:: Get the factorial of a number
::
:: call :factorial 7 RETURNVAR
:: echo %RETURNVAR%
::---------------------------------------------------------------------------------------
:factorial
setlocal
set "out=1"
for /l %%a in (%~1,-1,1) do set /a "out*=%%a"
if %~1 equ 0 set "out=1"
(endlocal
if "%~2" neq "" ( set "%~2=%out%" ) else echo %out%
)
goto :eof
:sqrt
::--------------------------------------------------------------------------------------------------
:: Square root a number
::
:: call :sqrt 144
:: call :sqrt 144 return_var
::
::--------------------------------------------------------------------------------------------------
:sqrt
setlocal
set "s=%~1"
set /A "x=s/(11*1024)+40,x=(s/x+x)>>1,x=(s/x+x)>>1,x=(s/x+x)>>1,x=(s/x+x)>>1,x=(s/x+x)>>1,x+=(s-x*x)>>31
(endlocal
if "%~2" neq "" ( set %~2=%x% ) else echo %x%
)
goto :eof
:specialCharacters
Spoiler (Click to Hide)
Code:
- Code:
:: obtain special characters BS, FF, BEL, CtrlZ, CR, LF, TAB
::
:: call :specialChars
::
:: %BS% = backspace
:: %BEL% = sound character
:: %FF% freeform female character
:: %CtrlZ% = Ctrl + Z
:: %CR% = Carriage return
:: %LF% = Line feed
::------------------------------------------------------------------------------
:specialChars
:: Backspace
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
:: FreeForm
>con ( for /f %%a in ('cls') do ( set "FF=%%a") )
:: BEL (sound)
for /f %%i in ('forfiles /m "%~nx0" /c "cmd /c echo 0x07"') do set "BEL=%%i"
:: Ctrl-Z 0x1A decimal 26
:zL
copy nul "%temp%\ctrlZ.tmp" /a <nul >nul
(for /f "usebackq" %%A in ("%temp%\ctrlZ.tmp") do set "CtrlZ=%%A")2>nul||goto :zL
del "%temp%\ctrlZ.tmp" 2>nul
:: Linefeed 0x0A decimal 10
(set LF=^
%= Do not remove or alter this line =%
)
:: Carriage Return 0x0D decimal 13
for /f %%A in ('copy /z "%~dpf0" nul') do set "CR=%%A"
:: Tab 0x09
for /f "delims=" %%T in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x09"') do set "TAB=%%T"
goto :eof
::------------------------------------------------------------------------------
:Neg_Or_Pos
:: call :Neg_or_Pos NUMBER [/p, /n, /r] outVAR
::
:: /p - records NUMBER to outVAR IF NUMBER is Positive
:: /n - records NUMBER to outVAR IF NUMBER is Negative
:: /r - records NUMBER to outVAR regardless
::
:: outVAR = any name you want, but must not contain variables.
:Neg_or_Pos
set "NoP_p2=%~2"
echo %1|findstr /c:"-" >nul 2>&1
if "!NoP_p2!" equ "" (
if !errorlevel! equ 1 echo %1 = Positive
if !errorlevel! equ 0 echo %1 = Negative
goto :eof
) else if not "!NoP_p2!" equ "" (
if /i "!NoP_p2:~1,1!" equ "p" if !errorlevel! equ 1 set "%~3=%1"
if /i "!NoP_p2:~1,1!" equ "n" if !errorlevel! equ 0 set "%~3=%1"
if /i "!NoP_p2:~1,1!" equ "r" set "%~3=%1"
)
set "NoP_p2="
:Grid
:: call :grid /A-Z NUMBER "boxHeightxboxWidth" /s
::
:: /A-Z is rows, allowing up to 26. Meaning you can have 26 boxes long.
::
:: NUMBER = Number of boxes tall
::
:: "boxHeightxboxWidth" = Height and Width of individual boxes
::
:: /s = OPTIONAL will display overlay data of grid.
::
::
:: call :grid /E 3 "5x9" /s
:grid
set "_t=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
set "gHeight=%2" & set "z=%1" & set "z=!z:~1,1!"
for %%a in (%_t%) do set /a "i+=1" & if /i "%%a" equ "%z%" set "gWidth=!i!"
for /f "tokens=1,2 delims=x" %%a in ("%~3") do set /a "bHeight=%%a + 1", "bWidth=%%b"
set /a "g=((gWidth * bWidth) + bWidth)", "gridMaxHeight=(gHeight * bHeight) + 1"
set /a "gridMaxWidth=g - bWidth + gWidth + 1", "_w=bWidth + 1"
for /l %%a in (1,1,%bWidth%) do set "s=!s! "
for /l %%a in (1,%bWidth%,%g%) do set "d=!d!!s!#"
for /l %%a in (1,1,%gridMaxHeight%) do set "line[%%a]=#!line[%%a]!!d:~0,-%bWidth%!"
for /l %%a in (1,1,%gridMaxWidth%) do set "line[0]=!line[0]!#"
for /l %%a in (1,%bHeight%,%gridMaxHeight%) do set "line[%%a]=!line[0]!"
if "%~4" equ "/s" set "ol=GRID: %gridMaxHeight%x%gridMaxWidth%/[A-%z%] x %gHeight%. - %~3 boxes"
:init_rainbow, :Rainbow_text
:: ---------------------------------------------------------------------------------------------------------------------------
:: Displays rainbow text up to 45 chars
::
:: call :init_rainbow
:: call :rainbow_text "TEXT
::
:: ---------------------------------------------------------------------------------------------------------------------------
:rainbow_text
set "str=x%~1" & <nul set /p ".=["
for %%a in (%rainbow_text%) do (
set /a "i+=1"
call set "ex_str=%%str:~!i!,1%%"
if "!ex_str!" equ "" ( <nul set /p ".=]" & echo. & goto :eof )
if "!ex_str!" equ " " (
<nul set /p ".=] ["
) else (
(> colorPrint.txt (echo [!ex_str!]\..\') && findstr /a:0%%a /f:colorPrint.txt ".")
)
)
:init_rainbow
set "rainbow_text=4 C 6 E 2 A 1 9 3 B 5 D F 7 8 0 4 C 6 E 2 A 1 9 3 B 5 D F 7 8 0 4 C 6 E 2 A 1 9 3 B 5 D F 7 8 0"
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E & echo on & for %%b in (1) do rem"') do set "DEL=%%a"
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" > "'"
goto :eof
CLICK ME :build_alphabet, :bigText
:: --------------------------------------------------------------------------------------------------------------------------------------------------------------------
:: :bigText displays color in desired from from :build_alphabet function (NOT COMPLETE)
::
:: call :bigText "Hello" 54 " " 1f "World" c3
:: --------------------------------------------------------------------------------------------------------------------------------------------------------------------
:bigText
setlocal
set "a=1"
:getArgs
if "%~1" neq "" set /a "args+=1" & set "t[!args!]=%~1"
if "%~2" neq "" set "c[!args!]=%~2"
shift & shift & if "%~1" neq "" ( goto :getArgs )
:getLetter
if defined t[%a%] (
set "e[%a%]=!t[%a%]:~%p%,1!" & set "cs=!e[%a%]!"
set /a "p+=1", "n[%a%]+=1"
set "cha[%a%][!n[%a%]!]=!cs!"
if "!cs!" equ "" set /a "a+=1", "p=0"
goto :getLetter
)
for /l %%c in (1,1,%b_a_btMAX%) do for /l %%a in (1,1,%args%) do for /l %%b in (1,1,!n[%%a]!) do call set "o[%%a][%%c]=!o[%%a][%%c]!%%_!cha[%%a][%%b]![%%c]%%"
for /l %%b in (1,1,%b_a_btMAX%) do ( for /l %%a in (1,1,%args%) do (>cp.txt ( echo=!o[%%a][%%b]!\..\') && findstr /a:!c[%%a]! /f:cp.txt ".") ) & echo.
endlocal
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|