Fractal: Dragon curve

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
neorobin
Posts: 47
Joined: 01 May 2012 12:18

Fractal: Dragon curve

#1 Post by neorobin » 14 Apr 2017 01:42

Image
Please replace the ★ in code by a real TAB (ASCII 0x09). Tested only on WIN7 64bit

Code: Select all

%1 @goto :initCON
@echo off & setlocal enabledelayedexpansion
call :clearVars
set /a "w=100,h=68, h1=h+0,t=w*h,xc=w/2+1,yc=h/2"

set "TAB=★" & for /F %%a in ('"prompt $h&for %%b in (1) do rem"')do Set "BS=%%a"
set /a "buffwid = w, linesWantBackAbove = h + 1 - 1, cntBS = 2 + (buffwid + 7) / 8 * linesWantBackAbove"
set "BSs=" & for /L %%a in (1 1 !cntBS!) do set "BSs=!BSs!%BS%"
set "aLineBS=" & for /L %%a in (1 1 !w!) do set "aLineBS=!aLineBS!%BS%"

mode %w%,%h1%

for /l %%i in (1 1 !t!) do set "s=!s! "
set "xv=-1" & set "yv=0 "

set "pttn=.@.@.@.@.@.@.@."
REM init curve
set /a "x=xinit=28, y=yinit=-10, length=1, len2=(length-1) * 2"
set /a "i=x-xc + (y-yc) * w + 1, L=i-1"
for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!!pttn:~0,1!!s:~%%b!)
for /L %%L in (0 2 !len2!) do (
    set /a "x += !xv:~%%L,2!, y += !yv:~%%L,2!"
    set /a "i=x-xc + (y-yc) * w + 1, L=i-1"
    for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!!pttn:~0,1!!s:~%%b!)
)
set "pttn=!pttn:~1!"
call :f !xinit! !yinit! !length! s xv yv
title complete & >nul pause &exit
:f xtail ytail length s xv yv
REM setlocal

    if %3 lss 4096 (

        set "vxr=" & set "vyr="

        set /a "x=%1, y=%2, len2=(%3 - 1) * 2, nextLength=%3 * 2"
        for /L %%L in (0 2 !len2!) do (
            set /a "xn = - !yv:~%%L,2!, yn = !xv:~%%L,2!"

            set /a "x += -xn, y += -yn" & rem xn,yn get the vector rotate 90deg, and then mltiply by -1
            set /a "i=x-xc + (y-yc) * w + 1, L=i-1, inScr=(x-(-w/2+1)^x-(w/2+1))&(y-(-h/2+1)^y-(h/2+1))"
            if !inScr! lss 0 (
                for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!!pttn:~0,1!!s:~%%b!)

                <nul set /p "=!aLineBS!" & (2>nul echo;%TAB%!BSs!) & <nul set /p "=%BS%"
                <nul set /p "=%BS%!s:~0,-1!"
            )

            set "xn=  !xn!" & set "yn=  !yn!"
            set "vxr=!xn:~-2!!vxr!" & set "vyr=!yn:~-2!!vyr!"
        )
        set "pttn=!pttn:~1!"

        set "xv=!vxr!!xv!" & set "yv=!vyr!!yv!"

        call :f !x! !y! !nextLength! %4 %5 %6
    )

exit /b

:initCON
@echo off
for %%a in (  FontSize:00080008      FontFamily:00000030  WindowSize:00C800C8
              ScreenColors:0000000f  CodePage:000001b5    ScreenBufferSize:00C800C8
) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do (
  >nul reg add HKCU\Console\Dragon_curve /v %%b /t reg_dword /d 0x%%c /f
)
start "Dragon_curve" /max "%ComSpec%" /c "%~0" REM & (call :delReg) & exit
REM end of :initCON
exit /b
:clearVars
set "Path=%SystemRoot%\system32"
for /f "delims==" %%a in ('set') do (
  if /i "%%a" neq "Path" set "%%a="
)
exit /b
REM end of :clearVars
:delReg
setlocal enabledelayedexpansion
set "s=!time:~-4,1!"
:delReg.loop
set /a "elapse = (1!time:~-4,1! - s) %% 10"
if %elapse% lss 2 goto :delReg.loop
>nul reg delete HKCU\Console\Dragon_curve /f
endlocal
exit /b
REM end of :delReg

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

Re: Fractal: Dragon curve

#2 Post by einstein1969 » 14 Apr 2017 10:16

Hi neorobin,

I have tested on italian windows 7 32bit and work well.

einstein1969

neorobin
Posts: 47
Joined: 01 May 2012 12:18

Re: Fractal: Dragon curve

#3 Post by neorobin » 14 Apr 2017 10:46

Hi, einstein1969

OK!

Thanks for your attention and feedback.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Fractal: Dragon curve

#4 Post by Ed Dyreen » 14 Apr 2017 21:22

cool, which program did you use to capture the animation in a gif ?

neorobin
Posts: 47
Joined: 01 May 2012 12:18

Re: Fractal: Dragon curve

#5 Post by neorobin » 14 Apr 2017 21:35

re: Ed Dyreen

Thanks!

ScreenToGif
https://screentogif.codeplex.com/

Sounak@9434
Posts: 100
Joined: 16 Dec 2016 22:31

Re: Fractal: Dragon curve

#6 Post by Sounak@9434 » 14 Apr 2017 23:55

@neorobin:
Tested and working beautifully on windows 8.1 32bit(x86)

neorobin
Posts: 47
Joined: 01 May 2012 12:18

Re: Fractal: Dragon curve

#7 Post by neorobin » 15 Apr 2017 03:04

re: Sounak@9434

Thanks for your feedback!

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Fractal: Dragon curve

#8 Post by Ed Dyreen » 15 Apr 2017 13:35

great, thanks neorobin

ps; tested successfully on windows eXperience professional

ps; you can create an executable from it using bat2exe and then rename the exe to scr and you have a screensaver

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Fractal: Dragon curve

#9 Post by Aacini » 16 Apr 2017 21:58

Tested successfully on Windows 8.1 Spanish, both 32 and 64 bits.

I reviewed the code and I think it is somewhat convoluted and with not enough descriptive comments, and it have multiple jumps that just makes it even less clear. I tried to understand the factors that makes it to select between "@" and "." in the drawing, and also to modify the recursive level and/or the graph coordinates, but that is a hard work... IMHO this type of code is not useful for others that may want to understand it and then modify it.

I developed my own version of a Dragon fractal curve drawing Batch program. I used my Turtle Graphics engine for Batch files and just changed the drawing example code section:

Code: Select all

:TurtleGraphics
rem Start of drawing commands
call :newwindow "Batch Turtle Graphics" 400 400

:nextCommand
   echo/
   echo Ready...
   set "command="
   set /P "command="
   if not defined command goto endCommands
   %command%
goto nextCommand
:endCommands

rem End of drawing commands
goto :EOF

... by the Dragon Curve drawing code, that is this one:

Code: Select all

:TurtleGraphics
rem Start of drawing commands

Title Drawing of Dragon Curve
rem The method used here is the one described just before Gray Code Method at:
rem https://en.wikipedia.org/wiki/Dragon_curve#Gray_code_method

set /A horSize=800, unit=horSize/10, verSize=unit*6, lineLen=unit*6, horPos=unit*23/10, verPos=unit, startAngle=45, adj=0

cls
echo/
echo Select this window and
for /L %%n in (1,1,14) do (
   set /P "=Press any key to draw the next level . . ." < NUL
   pause > NUL

   rem The adjustment in lineLen was tuned for a horSize of 800 pixels:
   if %%n lss 9 (set /A adj+=4) else if %%n equ 9 (set /A adj+=1) else if %%n equ 13 set /A adj-=2
   set /A "segments=1<<%%n, segLen=lineLen/%%n-adj"
   if %%n equ 1 set /A segLen=segLen*10/15
   echo/
   echo Drawing level %%n . . .

   call :newWindow "Dragon Curve - Level %%n: draw !segments! segments of !segLen! pixels" %horSize% %verSize%
   call :setxy -%horPos% -%verPos%
   call :right !startAngle!
   set /A "startAngle=(startAngle-45)%%360"

   for /L %%n in (1,1,!segments!) do (
      call :penDown
      call :forward !segLen!
      set /A "angle=((-2*^!^!(((%%n&-%%n)<<1)&%%n))+1)*90"
      call :right !angle!
      call :penUp
   )

)
pause

rem End of drawing commands
goto :EOF

The result is pretty good:

Image Image
Image Image
Image
Image

Antonio

neorobin
Posts: 47
Joined: 01 May 2012 12:18

Re: Fractal: Dragon curve

#10 Post by neorobin » 17 Apr 2017 01:48

Thanks, Ed Dyreen

But Win7 and after systems seems to be no full-screen feature

neorobin
Posts: 47
Joined: 01 May 2012 12:18

Re: Fractal: Dragon curve

#11 Post by neorobin » 17 Apr 2017 01:54

@Aacini, thank you for your attention and feedback.

I wrote a version with simple algorithm explain.
There is a good algorithm explain here: https://en.wikipedia.org/wiki/Dragon_curve
My algorithmic description version is just for my batch implementation code.

The first 9 turns curves and vectors results:

Code: Select all

TURN 1

vector_x=-1
vector_y=0

The tail position: (0, 0)



               H.+



TURN 2
   vector_x_prev=-1
   vector_y_prev=0

vector_x_reverse= 0
vector_y_reverse=-1

        vector_x= 0-1
        vector_y=-10

The tail position: (0, 2)



               H.+
                 .
                 T



TURN 3
   vector_x_prev= 0-1
   vector_y_prev=-10

vector_x_reverse= 0 1
vector_y_reverse=-1 0

        vector_x= 0 1 0-1
        vector_y=-1 0-10

The tail position: (-2, 4)



               H.+
                 .
               ..O
               .
               T



TURN 4
   vector_x_prev= 0 1 0-1
   vector_y_prev=-1 0-10

vector_x_reverse= 0 1 0 1
vector_y_reverse=-1 0 1 0

        vector_x= 0 1 0 1 0 1 0-1
        vector_y=-1 0 1 0-1 0-10

The tail position: (-6, 4)



               H.+
                 .
           ... ...
           . . .
           T ..O



TURN 5
   vector_x_prev= 0 1 0 1 0 1 0-1
   vector_y_prev=-1 0 1 0-1 0-10

vector_x_reverse= 0 1 0 1 0-1 0 1
vector_y_reverse=-1 0 1 0 1 0 1 0

        vector_x= 0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1
        vector_y=-1 0 1 0 1 0 1 0-1 0 1 0-1 0-10

The tail position: (-10, 0)



       ...
       . .
       T ...   H.+
           .     .
         ..... ...
         . . . .
         ..O ...



TURN 6
   vector_x_prev= 0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1
   vector_y_prev=-1 0 1 0 1 0 1 0-1 0 1 0-1 0-10

vector_x_reverse= 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1
vector_y_reverse=-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0

        vector_x= 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1
        vector_y=-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0 1 0-1 0-10

The tail position: (-10, -8)



       ...
       . .
       T ...
           .
         ...
         .
       .....
       . . .
     .......
     . . .
     ..O ...   H.+
           .     .
         ..... ...
         . . . .
         ... ...



TURN 7
   vector_x_prev= 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1
   vector_y_prev=-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0 1 0-1 0-10

vector_x_reverse= 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0-1 0-1 0 1 0-1 0-1 0-1 0-1 0 1
vector_y_reverse=-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0-1 0-1 0 1 0-1 0 1 0 1 0

        vector_x= 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0-1 0-1 0 1 0-1 0-1 0-1 0-1 0 1 0 1 0 1 0-1 0 1 0-
1 0-1 0-1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1
        vector_y=-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0-1 0-1 0 1 0-1 0 1 0 1 0-1 0 1 0 1 0 1 0 1
0-1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0 1 0-1 0-10

The tail position: (-2, -16)



               ...
               . .
               T ...
                   .
                 ...
                 .
       ... ... .....
       . . . . . . .
     ........... ...
     . . . . .
     ..O .......
           . . .
         ... ...
         .
       .....
       . . .
     .......
     . . .
     ... ...   H.+
           .     .
         ..... ...
         . . . .
         ... ...



TURN 8
   vector_x_prev= 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0-1 0-1 0 1 0-1 0-1 0-1 0-1 0 1 0 1 0 1 0-1 0 1 0-
1 0-1 0-1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1
   vector_y_prev=-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0-1 0-1 0 1 0-1 0 1 0 1 0-1 0 1 0 1 0 1 0 1
0-1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0 1 0-1 0-10

vector_x_reverse= 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0-1 0-1 0 1 0-1 0-1 0-1 0-1 0 1 0-1 0-1 0 1 0-1 0
1 0 1 0 1 0-1 0-1 0-1 0 1 0-1 0-1 0-1 0-1 0 1
vector_y_reverse=-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0-1 0-1 0 1 0-1 0 1 0 1 0 1 0-1 0-1 0-1 0-1
0 1 0-1 0-1 0 1 0-1 0-1 0-1 0 1 0-1 0 1 0 1 0

        vector_x= 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0-1 0-1 0 1 0-1 0-1 0-1 0-1 0 1 0-1 0-1 0 1 0-1 0
1 0 1 0 1 0-1 0-1 0-1 0 1 0-1 0-1 0-1 0-1 0 1 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0-1 0-1 0 1 0-1 0-1 0-
1 0-1 0 1 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1
        vector_y=-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0-1 0-1 0 1 0-1 0 1 0 1 0 1 0-1 0-1 0-1 0-1
0 1 0-1 0-1 0 1 0-1 0-1 0-1 0 1 0-1 0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0-1 0-1 0 1 0-1
0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0-1 0 1 0 1 0 1 0-1 0 1 0-1 0-10

The tail position: (14, -16)



               ... ...
               . . . .
             .........         ...
             . . . .           . .
             ..O ..... ...     T ...
                   . . . .         .
                 .........       ...
                 . . . .         .
       ... ... ........... ... .....
       . . . . . . . . . . . . . . .
     ........... ....... ....... ...
     . . . . .     . .     . .
     ... .......   .....   .....
           . . .     . .     . .
         ... ...     ...     ...
         .
       .....
       . . .
     .......
     . . .
     ... ...   H.+
           .     .
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 0-1 0 1 0 1 0-1 0 1 0 1 0 1 0 1 0-1 0 1 0 1 0-1
0 1 0 1 0 1 0-1 0 1 0-1 0-10

The tail position: (30, 0)



               ... ...         ... ...
               . . . .         . . . .
             .........       .........
             . . . .         . . . .
             ... ..... ...   ..O ..... ...
                   . . . .         . . . .
                 .........       .........
                 . . . .         . . . .
       ... ... ........... ... .........
       . . . . . . . . . . . . . . . .
     ........... ....... .............
     . . . . .     . .     . . . . .
     ... .......   .....   ........... ...
           . . .     . .     . . . . . . .
         ... ...     ...   ...............
         .                 . . . . . . .
       .....               .............
       . . .                 . . . . .
     .......               ..... .....         ...
     . . .                 . .     .           . .
     ... ...   H.+         .....   ... ...     T ...
           .     .           . .     . . .         .
         ..... ...           ...   .......       ...
         . . . .                   . . .         .
         ... ...                   ....... ... .....
                                     . . . . . . . .
                                   ..... ....... ...
                                   . .     . .
                                   .....   .....
                                     . .     . .
                                     ...     ...






Code: Select all

:: Dragon curve algorithmic description, neorobin @ 20170417_152348
:: This is an algorithmic description version, you can observe the changes of the variables and graphics to understand the details of the algorithm.
:: The point that is painted by the character "O" is the center of rotation;
:: The point that is painted by the character "+" is the coordinate system origin;
:: The point that is painted by the character "H" is the head of curve;
:: The point that is painted by the character "T" is the tail of curve;
:: algorithm explain here: https://en.wikipedia.org/wiki/Dragon_curve

%1 @goto :initCON  & rem Set the fontsize of the console
@echo off & setlocal enabledelayedexpansion

REM Initialize the screen panel settings
set /a "w = 100, h = 68, h1 = h + 9999, size = w * h, xc = w / 2 + 1, yc = h / 2"
mode %w%,%h1%
for /l %%i in (1 1 !size!) do set "s=!s! "
set "body_char=."



REM Draw the initial most basic and simple dragon curve -- a short straight line
set "vector_x=-1"
set "vector_y=0 "

echo;vector_x=!vector_x!
echo;vector_y=!vector_y!

set /a "x = xInit = 0, y = yInit = 0, length = 1, len2 = (length - 1) * 2"

REM The tail
call :setPixel !x! !y! T

for /L %%L in (0 2 !len2!) do (
    for %%a in (1 2) do (   rem The length of each basic line segment is 2
        set /a "x += !vector_x:~%%L,2!, y += !vector_y:~%%L,2!"
        call :setPixel !x! !y! !body_char!
    )
)
REM The head
call :setPixel !x! !y! H
call :setPixel 0 0 + & rem Mark the coordinate system origin

echo; & echo;The tail position: (!xInit!, !yInit!^)
echo;!s!

pause

call :f !xInit! !yInit! !length! s vector_x vector_y

echo;complete, any key to exit... & >nul pause &exit

:f xtail ytail length screen_var vector_x vector_y

    if %3 lss 2048 (

        REM The point that is painted by the letter "O" is the center of rotation
        set "s=!s:O=%body_char%!"
        set "s=!s:T=O!"

        set "vector_x_reverse="
        set "vector_y_reverse="

        set /a "x = %1, y = %2, len2 = (length-1) * 2"

        for /L %%L in (0 2 !len2!) do (

            REM Rotate 90 degrees and reverse
            set /a "x_step = - !vector_y:~%%L,2!, y_step = !vector_x:~%%L,2!"

            REM Draw The result of the prev curve rotate 90 degrees transformation
            for %%a in (1 2) do (
                set /a "x += -x_step, y += -y_step"
                call :setPixel !x! !y! !body_char!
            )

            REM Vectors reverse assembly, save to vector_x_reverse and vector_y_reverse
            set "x_step=  !x_step!"
            set "y_step=  !y_step!"
            set "vector_x_reverse=!x_step:~-2!!vector_x_reverse!"
            set "vector_y_reverse=!y_step:~-2!!vector_y_reverse!"
        )

        REM The tail
        call :setPixel !x! !y! T

        set "vector_x_prev=!vector_x!"
        set "vector_y_prev=!vector_y!"

        REM Assemble vector_x_reverse, vector_y_reverse to the front of the previous curve vectors
        set "vector_x=!vector_x_reverse!!vector_x!"
        set "vector_y=!vector_y_reverse!!vector_y!"

        echo;   vector_x_prev=!vector_x_prev!
        echo;   vector_y_prev=!vector_y_prev!
        echo;
        echo;vector_x_reverse=!vector_x_reverse!
        echo;vector_y_reverse=!vector_y_reverse!
        echo;
        echo;        vector_x=!vector_x!
        echo;        vector_y=!vector_y!
        echo; & echo;The tail position: (!x!, !y!^)

        call :setPixel 0 0 + & rem Mark the coordinate system origin
        echo;!s!
        pause

        REM The next turn curve total lenth is twice this turn
        set /a "length *= 2"

        call :f !x! !y! !length! %4 %5 %6
    )

exit /b

:setPixel x y char
set /a "i = %1-xc + (%2-yc) * w + 1, L = i-1, inScr = (x-(-w/2+1)^x-(w/2+1))&(y-(-h/2+1)^y-(h/2+1))"
if !inScr! lss 0 (
    for /f "tokens=1,2" %%a in ("!L! !i!") do (set s=!s:~0,%%a!%3!s:~%%b!)
)
exit /b


:initCON
@echo off
for %%a in (  FontSize:00080008      FontFamily:00000030  WindowSize:00C800C8
              ScreenColors:0000000f  CodePage:000001b5    ScreenBufferSize:00C800C8
) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do (
  >nul reg add HKCU\Console\Dragon_curve /v %%b /t reg_dword /d 0x%%c /f
)
start "Dragon_curve" /max "%ComSpec%" /c "%~0" REM & exit
exit /b

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

Re: Fractal: Dragon curve

#12 Post by einstein1969 » 17 Apr 2017 13:44

@neorobin
Have you tested the echo;%TAB%!BSs! with the "findstr colors"?

neorobin
Posts: 47
Joined: 01 May 2012 12:18

Re: Fractal: Dragon curve

#13 Post by neorobin » 17 Apr 2017 23:53

@einstein1969

I did a test to achieve the purpose of the cursor feed back multiple lines.

But I can not find a way to do cursor feed back and color output at the same time.

Code: Select all

@echo off

mode 15

for /L %%i in (1 1 5) do echo;Line %%i

REM The content of file @test is one TAB followed 10 BS, no other any more charactors.

findstr /A:0a . @test*

>nul pause

The output( the underline is the cursor position ):
Line 1
Line 2
Line 3
Line 4 _
Line 5
@test:

Post Reply