@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_curveMy 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.+
. .
..... ...
. . . .
... ...
TURN 9
vector_x_prev= 0 1 0 1 0-1 0 1 0-1 0-1 0-1 0 1 0-1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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