Fast draw circle/ellipse in dos batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Fast draw circle/ellipse in dos batch

#1 Post by einstein1969 » 23 May 2014 10:01

Hi,

This is subroutine for display small circle/ellipse very fast.

Can be optimizing enogh (making a macro or other) and my be consider a prof of concept.

If you are necessary a file with a circle this is an option.

Tested on windows 7 32bit

Code: Select all

@echo off

chcp 850
mode 80,43 >nul
cls

rem use font raster 8x8 for aspect ratio 1:1
rem Thanks at penpen and jeb!

(setlocal enableDelayedExpansion & for /F "delims==" %%f in ('set') do set "%%f="

call :init_circle

:: This use antiflicker using timers coaleshing. Work on windows 7
for /L %%\ in (0,1,18000) do (

  if not "!OT!"=="!time:~10,1!" (
    set /a "r=i %% 16-7, r=(r>>31|1)*r+2, i+=1"
    call :circle !r! 1
    set OT=!time:~10,1!
  )
)

:: This is without antiflicker
for /L %%\ in (0,1,30) do (

   set /a "r=i %% 16-7, r=(r>>31|1)*r+2, i+=1"
   call :circle !r! 1
   call :circle !r! 1*2/3
   call :circle !r! 2
   call :circle !r! 1*2/3
   call :circle !r! 1
   call :circle !r! 1*3/2
)

endlocal & goto :eof )


rem set "))=+%%y*%%y)/32)^^%1" : Setting a macro for partial formula. To reduce code dimension.
rem You can tune the number 32 for bigger o smaller circle and for thikness of circle and the radius. The %1 is the radius

:circle %1=radius %2=ratio/ellipse
(cls & type "%tmp%\circle.tmp.txt"
set "))=+%%y*%%y/%2)/32)^^(%~1)")
(set "))="
 (for /L %%y in (-%md%,1,%md%) do (
   set b=
   for /L %%x in (-%md%,4,%md%) do (
    set /a "a=10000+^!^!( (( %%x*%%x %))% ), a+=^!^!( (( (%%x+1)*(%%x+1) %))% )*10, a+=^!^!( (( (%%x+2)*(%%x+2) %))% )*100, a+=^!^!( (( (%%x+3)*(%%x+3) %))% )*1000"
    for /F "tokens=1-4" %%f in ("!a:~-1! !a:~-2,1! !a:~-3,1! !a:~-4,1!") do set b=!b!!c:~%%f,1!!c:~%%g,1!!c:~%%h,1!!c:~%%i,1!
   )
   echo(!b!
 )) > "%tmp%\circle.tmp.txt"
goto :eof )



:init_circle

  rem maximum dimension of circle or windows square
  set md=20

  rem charatcher used for draw a full/empty pixel
  set "c=Û "

goto :eof



EDIT: Add codepage.

einstein1969

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Fast draw circle/ellipse in dos batch

#2 Post by einstein1969 » 28 May 2014 09:24

Hi,

someone pointed out to me that the characters are not displayed well.

I added my code page (850) , where I developed.

Some expert tell me if it is enough or you need to create binary as suggested by miskox in this thread?

einstein1969

miskox
Posts: 642
Joined: 28 Jun 2010 03:46

Re: Fast draw circle/ellipse in dos batch

#3 Post by miskox » 28 May 2014 13:37

What character should we see at the bottom of the code? Can you show us a print screen?

Code: Select all

rem charatcher used for draw a full/empty pixel
  set "c=Û "


Image

When I run the .cmd:

Image


There was a problem with SetFilePointer.com from Aacini - I just couldn't paste the correct information to the file because of different forum codepages we use all over the world. After Aacini changed the code to hex it was Ok.

Saso

Post Reply