Advertisement
FlyFar

Fast Mandelbrot

Jun 28th, 2023
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 7.40 KB | Cybersecurity | 0 0
  1. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2. :: Mandelbrot
  3. ::
  4. :: Use font raster 8x8 or Lucida console 5
  5. ::
  6. :: For use +double Y resolution must disable ClearType but Activate Smoothness font edge in System preference. Sperimental mode.
  7. ::
  8. :: Tested on Windows 7 32bit
  9. ::
  10. :: v 0.2a New Features: Double resolution in Y
  11. ::  - Alpha stage for double resolution in Y. Only 16 color is permitted.
  12. ::  - Speed slow for maintain code small.
  13. ::  - TODO: double resolution in X, software dithering, resolve bug on queue double resolution
  14. ::
  15. :: v.0.1 Initial Version. Based on Aacini/jeb code.
  16. ::
  17. ::  - Tune Env + Implemented a queue for speedup call of findstr, quadruple speed!
  18. ::  - rewritten core of Iteration , 10% more Speed
  19. ::  - fixed bug that overflow the core iteration loop. Reduce FixedPoint precis. from 4 to 3 digit.
  20. ::  - Flips X coordinates to match with real Mandelbrot
  21. ::  - Palette rainbow!
  22. ::
  23. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  24. @echo off & Setlocal EnableDelayedExpansion
  25. cls
  26.  
  27.  :: for raster 8x8
  28.  mode 88,60
  29.  
  30.  :: for raster 6x4
  31. rem mode 188,100
  32.  
  33.  :: for Lucida console 5
  34. rem mode 330,140
  35.  
  36.  :: for Lucida console 2 Bold (Half resolution / Hardware dither)
  37. rem mode 480,360
  38.  
  39.  :: for Lucida console 2 (Hardware dither)
  40. rem mode 960,360
  41.  
  42.  :: Sperimental!!!
  43. :: Use +double Y resolution/16 color with software dithering or single resolution/256 color with hardware dithering
  44. rem set Double=TRUE
  45.  
  46.  call :init
  47.  
  48.  :: increase the queue lenght for more speed! QueueLen=1 => Disabled, 16=lowresolution 128=Highresolution
  49.  set MaxQueueLen=2
  50.  
  51.  :: Q=current queue Len
  52.  set Q=0
  53.  
  54.  rem 1=42 2=71 3=90 4=105 6=125 8=138 16=160 chars/sec
  55.  
  56.  rem                                X
  57. rem               X                X
  58. rem           X   X                X
  59. rem       X   X   X                X
  60. rem     X X   X   X                X
  61. rem   X X X   X   X                X
  62. rem X X X X   X   X                X
  63. rem X X X X   X   X                X
  64. rem 1 2 3 4   6   8                16
  65.  
  66.  REM Working values: maximum screen coordinates and iteration level
  67.  set /A maxX=Cols-15, maxY=Lines-5, maxLevel=48, one=1000
  68.  
  69.  :: to 3 decimal because go overflow.
  70.  call :IntAsFP   xLeft=-2.100
  71.  call :IntAsFP    yTop= 1.125
  72.  call :IntAsFP  xRight= 0.800
  73.  call :IntAsFP yBottom=-1.125
  74.  
  75. rem goto :n
  76.  set maxLevel=56
  77.  call :IntAsFP   xLeft=-0.420
  78.  call :IntAsFP    yTop= 1.000
  79.  call :IntAsFP  xRight= 0.250
  80.  call :IntAsFP yBottom= 0.580
  81. :n
  82.  
  83.  set /A "xStep=(xRight-xLeft)/maxX, yStep=(yTop-yBottom)/maxY, four=4*one*one"
  84.  
  85.  cls
  86.  echo(&echo(
  87.  
  88.  set t0=%time%
  89.  
  90. (
  91. :: remove unnecessary vars.
  92.  set t0=
  93. rem set MaxqueueLen=
  94. rem set one=
  95.  set MaxX=
  96.  set MaxY=
  97. rem set MaxLevel=
  98.  set Lines=
  99.  set Cols=
  100. rem set FS=
  101. rem set four=
  102. rem set Color_0=
  103. rem set Char_0=
  104.  set mBS=
  105.  set BS=
  106.  set yTop=
  107.  set yBottom=
  108.  set xRight=
  109.  set xLeft=
  110.  set yStep=
  111.  set xStep=
  112.  
  113.  set /A a_Cy=%yTop%+%yStep%, nChar=0
  114.  
  115.  for /L %%y in (0,1,%maxY%) do (
  116.  
  117.    set /P ".=%BS%       " <NUL
  118.    set /A a_Cy-=%yStep%, a_Cx=%xLeft%-%xStep%
  119.  
  120.    for /L %%x in (0,1,%maxX%) do (
  121.  
  122.       rem title %xStep% %yStep%
  123.  
  124.       set /A a_Cx+=%xStep%
  125.  
  126.       call :I
  127.  
  128.       if /I "!Double!"=="TRUE" (
  129.          set co1=!col!
  130.  
  131.          set /A "a_Cy+=(%yStep%/2)"
  132.  
  133.          call :I
  134.  
  135.          if "!col!"=="!co1!" (
  136.            set char=Û
  137.            set col=7!col!
  138.          ) else set Col=!col:~0,1!!co1:~0,1!
  139.  
  140.          set /A "a_Cy-=(%yStep%/2)"
  141.       )
  142.  
  143.         rem ex call :ColorText !showColor[%%l]! "!showChar[%%l]!"
  144.        rem ex (echo !showChar[%%l]!\..\') > colorPrint.txt & findstr /a:!showColor[%%l]! /f:colorPrint.txt "."
  145.  
  146.         rem TODO: Use this coloring : (echo Ü)> colorPrint.txt & %FS% /a:%1%2 /f:colorPrint.txt "."
  147.  
  148.       call :Q
  149.  
  150.  
  151.  
  152.    )
  153.   rem End of Line. flush queue
  154.    if defined QueueChar (
  155.      (echo !QueueChar!\..\') > colorPrint.txt & %FS% /a:!QueueColor! /f:colorPrint.txt "."
  156.      set QueueChar=
  157.      set QueueColor=
  158.      set Q=0
  159.    )
  160.   :: Performance Statistic.
  161.    for /F "tokens=1-8 delims=:.," %%a in ("%t0: =0%:!time: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, Cs=nChar*100*10/a"
  162.    title !cs:~0,-1!.!cs:~-1! Chars/sec
  163.    set cs=& set a=
  164.    echo(
  165.  )
  166.  
  167. )
  168.  
  169.  rem set
  170.  
  171.  popd
  172.  
  173. goto :EOF
  174.  
  175. :Q
  176. (
  177.        rem if queue full than flush and queue
  178.         if !Q! geq %MaxQueueLen% (
  179.            (echo !QueueChar!\..\') > colorPrint.txt & %FS% /a:!QueueColor! /f:colorPrint.txt "."
  180.            set QueueChar=!char!
  181.            set QueueColor=!col!
  182.            set Q=1
  183.         ) else (
  184.          rem if same color than queue
  185.           if "!QueueColor!"=="!col!" (
  186.              set QueueChar=!QueueChar!!char!
  187.              set /a Q+=1
  188.           ) else (
  189.           rem not same color. Flush and queue
  190.            if defined QueueChar ( (echo !QueueChar!\..\') > colorPrint.txt & %FS% /a:!QueueColor! /f:colorPrint.txt "." )
  191.            set QueueChar=!char!
  192.            set QueueColor=!col!
  193.            set Q=1
  194.           )
  195.         )
  196.  
  197. exit /b )
  198.  
  199. :I
  200. (
  201.       set /a $x=a_Cx, $y=a_Cy, $m=$x*$x+$y*$y
  202.       set bLev=
  203.      
  204.       :: check overflow!
  205.       for /L %%i in (1,1,%maxLevel%) do if not defined bLev (
  206.         if !$m! lss %four% (
  207.                set /A "a=2*$x*$y/%one%+a_Cy, $x=($m-2*$y*$y)/%one%+a_Cx, $y=a, $m=$x*$x+$y*$y"
  208.         ) else set bLev=%%i
  209.       )
  210.  
  211.       if not defined bLev set bLev=0
  212.  
  213.       for %%l in (!bLev!) do (
  214.  
  215.         :: color/char mapping
  216.         if /I "!Double!"=="TRUE" (
  217.           set /a "ic=0, ico=((%%l-1) %% 12) * 3,  nChar+=1"
  218.          :: Hybrid system color for test.
  219.          rem set /a "ic=((%%l-1) %% 4), ico=((%%l-1)/4 %% 12)*3, nChar+=1"
  220.         ) else set /a "ic=((%%l-1) %% 4), ico=((%%l-1)/4 %% 12)*3, nChar+=1"
  221.  
  222.         if %%l gtr 0 (
  223.            for %%i in (!ic!) do set char=!chars:~%%i,1!
  224.            for %%i in (!ico!) do set col=!Colors:~%%i,3!
  225.         ) else (
  226.           set char=%char_0%
  227.           set col=%Color_0%
  228.         )
  229.       )
  230.  
  231.       set ic=& set ico=
  232.  
  233.  
  234. exit /b )
  235.  
  236.  
  237. :IntAsFP Int=FP
  238.    set FP=%2
  239.    If "!FP:~0,1!"=="-" (
  240.       set FP=!FP:~1!
  241.       set sign=-
  242.    )
  243.    If "!FP:~0,1!"=="0" set FP=!FP:~1!
  244.    set %1=!sign!!FP:.=!
  245.    set FP=
  246.    set sign=
  247. exit /B
  248.  
  249. :Init
  250.    pushd %tmp%
  251.  
  252.    for /f %%f in ('where findstr') do set FS=%%f
  253.  
  254.    :: get currenct lines and columns from mode command.
  255.    for /f "skip=2 tokens=2" %%f in ('mode con:') do if not defined Lines (set Lines=%%f) else if not defined Cols set Cols=%%f
  256. (
  257.    for /F "Tokens=1 delims==" %%v in ('set') do set "%%v="
  258.    set /a Lines=%Lines%, Cols=%Cols%
  259.    set FS=%FS%
  260.    set Double=%Double%
  261. )
  262.    for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
  263.    set mBS=%BS%%BS%%BS%%BS%%BS%%BS%
  264.    <nul >"'" set /p ".=%mBS%      %mBS%"
  265.    <nul >"Ü" set /p ".=%BS%"
  266.  
  267.    :: Setting Color palette
  268.    if /I "!Double!"=="TRUE" (
  269.       set "chars=Ü"
  270.       set "char_0=Ü"
  271.  
  272.       set "Colors=4  C  E  A  2  2  3  B  9  1  5  D  "
  273.       set "Color_0=0"
  274.    ) else (
  275.       set "chars=°±²Û"
  276.       set "char_0=ú"
  277.  
  278.       set "Colors=04 4C CE EA A2 22 2A AB B9 91 15 50 "
  279.       set "Color_0=a"
  280.    )
  281.  
  282.      :: Hybrid system color for test.
  283.     rem set "chars=ÛÛÛÛ"
  284.     rem set "chars=ÜÜÜÜ"
  285.     rem set "char_0=ú"
  286.     rem set "Colors=4  C  E  A  2  2  3  B  9  1  5  D  "
  287.     rem set "Color_0=0"
  288.  
  289. goto :eof
Tags: mandelbrot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement