Advertisement
IcarusLives

HF Demo

Mar 4th, 2017
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.22 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2.  
  3. call :canvas 67 67
  4.  
  5. :: :ellipse x y r
  6. :: :rect x y h w
  7. :: :plot x y
  8. :: :plotLine x0 y0 x1 y1
  9.  
  10. set "ellipseSet=1 3 5 7 9 11 13 15 13 11 9 7 5 3 1"
  11. set "plotLineSet="5 5 60 60" "33 5 33 60" "60 5 5 60" "5 33 60 33""
  12. set "rectSet="28 27 10 10" "26 25 14 14" "24 23 18 18" "22 21 22 22" "20 19 26 26""
  13. :: ----------------------------------------------------------------
  14. :: ellipse x y r Demo
  15. REM :: ----------------------------------------------------------------
  16. :: "puddle" effect
  17. for %%a in (%ellipseSet% %ellipseSet:~1% %ellipseSet:~1%) do (
  18.  
  19.     call :ellipse 33 33 %%a
  20.  
  21.     call :showCanvas
  22.     call :updateCanvas
  23. )
  24. :: ----------------------------------------------------------------
  25. :: plotLine x0 y0 x1 y1 Demo
  26. :: ----------------------------------------------------------------
  27. :: spinning line
  28. for %%a in (%plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet% %plotLineSet%) do (
  29.  
  30.     call :plotLine %%~a
  31.    
  32.     call :showCanvas
  33.     call :updateCanvas
  34. )
  35. :: ----------------------------------------------------------------
  36. :: rect x y h w Demo
  37. :: ----------------------------------------------------------------
  38. ::
  39. for %%a in (%rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet% %rectSet%) do (
  40.  
  41.     call :rect %%~a
  42.    
  43.     call :showCanvas
  44.     call :updateCanvas
  45. )
  46. :: ----------------------------------------------------------------
  47. :: plot x y Demo
  48. :: ----------------------------------------------------------------
  49. :: Looks like starfield! I like this one.
  50. for /l %%a in (1,1,50) do ( for /l %%b in (1,1,50) do (
  51.  
  52.         set /a "r1=!random! %% width + 1", "r2=!random! %% height + 1"
  53.        
  54.         call :plot !r1! !r2!
  55.     )
  56.     call :showCanvas
  57.     call :updateCanvas
  58. )
  59. :: ----------------------------------------------------------------
  60.  
  61. timeout /t 3 /nobreak >nul & exit
  62. :: ----------------------------------------------------------------------------------------------------------------------------
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. :canvas
  70.     set /a "width=%~1 - 1", "height=%~2 - 1", "_=-1"
  71.     set /a "conWidth=width + 4", "conHeight=height + 5"
  72.     if exist cursorpos.exe ( set "cls=cursorpos 0 0" ) else ( set "cls=cls" )
  73.     call :updateCanvas
  74.     for %%a in (heightBuffer widthBuffer) do set "%%a="
  75.     mode con: cols=%conWidth% lines=%conHeight%
  76.     goto :eof
  77.    
  78.     :updateCanvas
  79.         for /l %%a in  (0,1,%width%) do set "widthBuffer=!widthBuffer! "
  80.         for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
  81.         for /l %%a in (0,1,%height%) do set "heightBuffer=!heightBuffer!"%widthBuffer%" "
  82.         for %%a in  (%heightBuffer%) do set /a "_+=1" & set "_[!_!]=%%~a"
  83.         for %%a in (widthBuffer heightBuffer _) do set "%%a="
  84.     goto :eof
  85.    
  86.     :showCanvas
  87.         %cls%
  88.         echo=%outerBuffer%
  89.         for /l %%a in (0,1,%height%) do echo=#!_[%%a]!#
  90.         echo=%outerBuffer%
  91.         set "outerBuffer="
  92.     goto :eof
  93. goto :eof
  94.  
  95. :plotLine x0 y0 x1 y1
  96.     set /a "x0=%~1", "y0=%~2", "x1=%~3", "y1=%~4", "dx=x1 - x0", "dy=y1 - y0"
  97.    
  98.     if %dy% lss 0 ( set /a "dy=-dy", "stepy=-1" ) else ( set /a "stepy=1")
  99.     if %dx% lss 0 ( set /a "dx=-dx", "stepx=-1" ) else ( set /a "stepx=1")
  100.    
  101.     set /a "dx<<=1", "dy<<=1"
  102.  
  103.     if %dx% gtr %dy% (
  104.         set /a "fraction=dy - (dx >> 1)"
  105.         for /l %%x in (%x0%,%stepx%,%x1%) do (
  106.             if !fraction! geq 0 (
  107.                 set /a "y0+=stepy"
  108.                 set /a "fraction-=dx"
  109.             )
  110.             set /a "fraction+=dy"
  111.             if 0 leq %%x if %%x lss %width% if 0 leq !y0! if !y0! lss %width% (
  112.                 call :plot %%x !y0!
  113.             )
  114.         )
  115.     ) else (
  116.         set /a "fraction=dx - (dy >> 1)"
  117.         for /l %%y in (%y0%,%stepy%,%y1%) do (
  118.             if !fraction! geq 0 (
  119.                 set /a "x0+=stepx"
  120.                 set /a "fraction-=dy"
  121.             )
  122.             set /a "fraction+=dx"
  123.             if 0 leq !x0! if !x0! lss %width% if 0 leq %%y if %%y lss %width% (
  124.                 call :plot !x0! %%y
  125.             )
  126.         )
  127.     )
  128.     for %%a in (x0 y0 x1 y1 dx dy stepx stepy fraction) do set "%%a="
  129. goto :eof
  130.  
  131. :plot x y
  132.     setlocal
  133.         set /a "_x2=%~1 + 1"
  134.         (endlocal
  135.             set "_[%~2]=!_[%~2]:~0,%~1!.!_[%~2]:~%_x2%!"
  136.             if "%~3" neq "" set "plot[%~1,%~2]="
  137.         )
  138. goto :eof
  139.  
  140. :swap
  141.     setlocal
  142.         set "temp=!%~1!"
  143.         (endlocal
  144.             set "%~1=!%~2!"
  145.             set "%~2=%temp%"
  146.         )
  147. goto :eof
  148.  
  149. :ellipse x y r
  150.     for /l %%y in (-%~3,1,%~3) do for /l %%x in (-%~3,1,%~3) do (
  151.        
  152.         set /a "S=(%%x * %%x) + (%%y * %%y) - (%~3 * %~3) - 1", "t=-%~3 - 1"
  153.         if !S! geq !t! if !S! leq 1 ( set /a "x=%%x + %~1", "y=%%y + %~2" & call :plot !x! !y! )
  154.        
  155.     )
  156. goto :eof
  157.  
  158. :rect x y h w
  159.     set /a "rect_x=%~1", "rect_y=%~2", "rect_h=%~2 + %~4", "rect_w=%~1 + %~3"
  160.     call :plotLine %rect_x% %rect_y% %rect_w% %rect_y%
  161.     call :plotLine %rect_x% %rect_y% %rect_x% %rect_h%
  162.     call :plotLine %rect_w% %rect_h% %rect_w% %rect_y%
  163.     call :plotLine %rect_w% %rect_h% %rect_x% %rect_h%
  164.     for %%a in (rect_h rect_w rect_x rect_y) do set "%%a="
  165. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement