Advertisement
IcarusLives

:plotLine x0 y0 x1 y1

Mar 4th, 2017
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.71 KB | None | 0 0
  1. :: -------------------------------------------------------------------------------------------
  2. :: :plotLine x0 y0 x1 y1  requires :canvas, :showCanvas, :plot
  3. ::
  4. :: call :canvas 30 30
  5. ::
  6. :: call :plotLine 14 6 24 23
  7. ::
  8. :: call :showCanvas
  9. ::
  10. :: -------------------------------------------------------------------------------------------
  11. :plotLine x0 y0 x1 y1
  12.     set /a "__x0=%~1", "__y0=%~2", "__x1=%~3", "__y1=%~4", "__dx=__x1 - __x0", "__dy=__y1 - __y0"
  13.    
  14.     if %__dy% lss 0 ( set /a "__dy=-__dy", "stepy=-1" ) else ( set /a "stepy=1")
  15.     if %__dx% lss 0 ( set /a "__dx=-__dx", "stepx=-1" ) else ( set /a "stepx=1")
  16.     set /a "__dx<<=1", "__dy<<=1"
  17.  
  18.     if %__dx% gtr %__dy% (
  19.         set /a "fraction=__dy - (__dx >> 1)"
  20.         for /l %%x in (%__x0%,%stepx%,%__x1%) do (
  21.             if !fraction! geq 0 (
  22.                 set /a "__y0+=stepy"
  23.                 set /a "fraction-=__dx"
  24.             )
  25.             set /a "fraction+=__dy"
  26.             if 0 leq %%x if %%x leq %width% if 0 leq !__y0! if !__y0! leq %height% (
  27.                 call :plot %%x !__y0! %5
  28.             )
  29.         )
  30.     ) else (
  31.         set /a "fraction=__dx - (__dy >> 1)"
  32.         for /l %%y in (%__y0%,%stepy%,%__y1%) do (
  33.             if !fraction! geq 0 (
  34.                 set /a "__x0+=stepx"
  35.                 set /a "fraction-=__dy"
  36.             )
  37.             set /a "fraction+=__dx"
  38.             if 0 leq !__x0! if !__x0! leq %width% if 0 leq %%y if %%y leq %height% (
  39.                 call :plot !__x0! %%y %5
  40.             )
  41.         )
  42.     )
  43.     for %%a in (__x0 __y0 __x1 __y1 __dx __dy stepx stepy fraction) do set "%%a="
  44. goto :eof
  45. :: -------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement