TGC Codebase Backup



Line Plotter by Mark Garrett

17th Feb 2006 9:48
Summary

draws a dot-line from one screen coordinate to the next. Line plotter simply takes the largest span between 2 coordinates (let's say 'y' is the largest span between 2 coordinates)



Description

A way of drawing lines between 2 coordinates on the screen without using the 'line' command and doing it with dots only...

example-
draw a line between coordinate'a' and coordinate'b'=

where
coordinate'a' = x 100, y 500

and
coordinate'b' = x1 400, y1 600


x1 - x = 300
y1 - y = 100

'x'span = 300
'y'span = 100

'x'span / 'y'span = 3

addition'y' = y 3

thus:

dot 1 = x100, y500
dot 2 = x101, y503
dot 3 = x102, y506
dot 4 = x103, y509 etc. etc. till the line is drawn completely from coordinate-a to coordinate-b





Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem Project: lineplot
Rem Created: 17.2.2006 6:35:36

Rem ***** Main Source File *****
Rem Project: MouseArrowLineDrawer
Rem Created: 31.7.2005 11:37:11




set display mode 1024,768,16

ink rgb(24,165,183),0
set cursor 10,10: print "press left mouse button"
wait 1
mxsa = 0: mysa = 0
sync on: sync rate 0
do
mx = mousex(): my = mousey()
if mouseclick() = 1 then dotline(mxsa,mysa,mx,my):mxsa = mx: mysa = my

rem sync
loop
rem suspend for key

function dotline(x1 as integer, y1 as integer,x2 as integer,y2 as integer)


x1# = x1: y1# = y1:x2# = x2: y2# = y2
if x1#> x2# then xspan# = (x1# - x2#): goto getyspan
xspan# = (x2# - x1#)

getyspan:
if y1#> y2# then yspan# = (y1# - y2#): goto whichspanbiggest
yspan# = (y2# - y1#)

whichspanbiggest:
if xspan# > yspan# then goto dox

doy:
if y1# > y2# then y1# = y2: y2# = y1: x1# = x2: x2# = x1
addx# = (xspan# / yspan#)
if x1# > x2# then addx# = (0 - addx#)

doy1: dot x1#,y1#
inc y1#: x1# = (x1# + addx#): if y1# >= y2# then goto done
goto doy1
`-----------------------------------------------------------------------------
dox:
if x1# > x2# then x1# = x2: x2# = x1: y1# = y2: y2# = y1
addy# = (yspan# / xspan#)
if y1# > y2# then addy# = (0 - addy#)

dox1: dot x1#,y1#
inc x1#: y1# = (y1# + addy#): if x1# >= x2# then goto done
goto dox1





done:
sync
endfunction