Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- call :canvas 67 67
- :: :ellipse x y r
- :: :rect x y h w
- :: :plot x y
- :: :plotLine x0 y0 x1 y1
- set "ellipseSet=1 3 5 7 9 11 13 15 13 11 9 7 5 3 1"
- set "plotLineSet="5 5 60 60" "33 5 33 60" "60 5 5 60" "5 33 60 33""
- set "rectSet="28 27 10 10" "26 25 14 14" "24 23 18 18" "22 21 22 22" "20 19 26 26""
- :: ----------------------------------------------------------------
- :: ellipse x y r Demo
- REM :: ----------------------------------------------------------------
- :: "puddle" effect
- for %%a in (%ellipseSet% %ellipseSet:~1% %ellipseSet:~1%) do (
- call :ellipse 33 33 %%a
- call :showCanvas
- call :updateCanvas
- )
- :: ----------------------------------------------------------------
- :: plotLine x0 y0 x1 y1 Demo
- :: ----------------------------------------------------------------
- :: spinning line
- for %%a in (%plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet%) do (
- call :plotLine %%~a
- call :showCanvas
- call :updateCanvas
- )
- :: ----------------------------------------------------------------
- :: rect x y h w Demo
- :: ----------------------------------------------------------------
- ::
- for %%a in (%rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet%) do (
- call :rect %%~a
- call :showCanvas
- call :updateCanvas
- )
- :: ----------------------------------------------------------------
- :: plot x y Demo
- :: ----------------------------------------------------------------
- :: Looks like starfield! I like this one.
- for /l %%a in (1,1,50) do ( for /l %%b in (1,1,50) do (
- set /a "r1=!random! %% width + 1", "r2=!random! %% height + 1"
- call :plot !r1! !r2!
- )
- call :showCanvas
- call :updateCanvas
- )
- :: ----------------------------------------------------------------
- timeout /t 3 /nobreak >nul & exit
- :: ----------------------------------------------------------------------------------------------------------------------------
- :canvas
- set /a "width=%~1 - 1", "height=%~2 - 1", "_=-1"
- set /a "conWidth=width + 4", "conHeight=height + 5"
- if exist cursorpos.exe ( set "cls=cursorpos 0 0" ) else ( set "cls=cls" )
- call :updateCanvas
- for %%a in (heightBuffer widthBuffer) do set "%%a="
- mode con: cols=%conWidth% lines=%conHeight%
- goto :eof
- :updateCanvas
- for /l %%a in (0,1,%width%) do set "widthBuffer=!widthBuffer! "
- for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
- for /l %%a in (0,1,%height%) do set "heightBuffer=!heightBuffer!"%widthBuffer%" "
- for %%a in (%heightBuffer%) do set /a "_+=1" & set "_[!_!]=%%~a"
- for %%a in (widthBuffer heightBuffer _) do set "%%a="
- goto :eof
- :showCanvas
- %cls%
- echo=%outerBuffer%
- for /l %%a in (0,1,%height%) do echo=#!_[%%a]!#
- echo=%outerBuffer%
- set "outerBuffer="
- goto :eof
- goto :eof
- :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
- :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
- :swap
- setlocal
- set "temp=!%~1!"
- (endlocal
- set "%~1=!%~2!"
- set "%~2=%temp%"
- )
- goto :eof
- :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
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement