RosettaCodeData/Task/Bitmap-Midpoint-circle-algorithm/Batch-File/bitmap-midpoint-circle-algorithm.bat

73 lines
1.5 KiB
Batchfile
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
@echo off
setlocal enabledelayedexpansion
2026-04-30 12:34:36 -04:00
%== Initializations ==%
2023-07-01 11:58:00 -04:00
set width=50
set height=30
set /a allowance=height+2
mode %width%,%allowance%
echo Rendering...
set "outp="
for /l %%i in (1,1,%height%) do (
2026-04-30 12:34:36 -04:00
for /l %%j in (1,1,%width%) do (
set "c[%%i][%%j]= "
)
2023-07-01 11:58:00 -04:00
)
2026-04-30 12:34:36 -04:00
%== Set the parameters for making circle ==%
2023-07-01 11:58:00 -04:00
call :DrawCircle 20 20 10
call :DrawCircle 10 30 15
2026-04-30 12:34:36 -04:00
%== Output result ==%
2023-07-01 11:58:00 -04:00
for /l %%i in (1,1,%height%) do (
2026-04-30 12:34:36 -04:00
for /l %%j in (1,1,%width%) do (
set "outp=!outp!!c[%%i][%%j]!"
)
2023-07-01 11:58:00 -04:00
)
cls
echo !outp!
pause>nul
exit /b
2026-04-30 12:34:36 -04:00
%== The main function ==%
2023-07-01 11:58:00 -04:00
:DrawCircle
2026-04-30 12:34:36 -04:00
set x0=%1
set y0=%2
set radius=%3
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
set x=!radius!
set y=0
set /a decisionOver2 = 1 - !x!
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
:circle_loop
if !x! geq !y! (
set /a "hor=x + x0","ver=y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=y + x0","ver=x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-x + x0","ver=y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-y + x0","ver=x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-x + x0","ver=-y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-y + x0","ver=-x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=x + x0","ver=-y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=y + x0","ver=-x + y0"
set "c[!hor!][!ver!]=Û"
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
set /a y+=1
if !decisionOver2! leq 0 (
set /a "decisionOver2 = !decisionOver2! + (2 * y^) + 1"
) else (
set /a x-=1
set /a "decisionOver2 = !decisionOver2! + 2 * (y - x^) + 1"
)
goto circle_loop
)
2023-07-01 11:58:00 -04:00
goto :EOF