Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: -------------------------------------------------------------------------------------------
- :: :plotLine x0 y0 x1 y1 requires :canvas, :showCanvas, :plot
- ::
- :: call :canvas 30 30
- ::
- :: call :plotLine 14 6 24 23
- ::
- :: call :showCanvas
- ::
- :: -------------------------------------------------------------------------------------------
- :plotLine x0 y0 x1 y1
- set /a "__x0=%~1", "__y0=%~2", "__x1=%~3", "__y1=%~4", "__dx=__x1 - __x0", "__dy=__y1 - __y0"
- if %__dy% lss 0 ( set /a "__dy=-__dy", "stepy=-1" ) else ( set /a "stepy=1")
- if %__dx% lss 0 ( set /a "__dx=-__dx", "stepx=-1" ) else ( set /a "stepx=1")
- set /a "__dx<<=1", "__dy<<=1"
- if %__dx% gtr %__dy% (
- set /a "fraction=__dy - (__dx >> 1)"
- for /l %%x in (%__x0%,%stepx%,%__x1%) do (
- if !fraction! geq 0 (
- set /a "__y0+=stepy"
- set /a "fraction-=__dx"
- )
- set /a "fraction+=__dy"
- if 0 leq %%x if %%x leq %width% if 0 leq !__y0! if !__y0! leq %height% (
- call :plot %%x !__y0! %5
- )
- )
- ) else (
- set /a "fraction=__dx - (__dy >> 1)"
- for /l %%y in (%__y0%,%stepy%,%__y1%) do (
- if !fraction! geq 0 (
- set /a "__x0+=stepx"
- set /a "fraction-=__dy"
- )
- set /a "fraction+=__dx"
- if 0 leq !__x0! if !__x0! leq %width% if 0 leq %%y if %%y leq %height% (
- call :plot !__x0! %%y %5
- )
- )
- )
- for %%a in (__x0 __y0 __x1 __y1 __dx __dy stepx stepy fraction) do set "%%a="
- goto :eof
- :: -------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement