Drawing patterned lines.

Every now and then people have asked whether they can draw patterned lines in LB, rather than the continuous ones that are built in. The answer is yes, if you take charge of drawing your choice of symbols along the known path, as in these examples..

-

The following code shows how this can be done- you can select spacing, colour and size of the 'marks'.


nomainwin

WindowWidth =800: WindowHeight =600

open "Dot & dashed lines" for graphics_nsb as #w

#w "trapclose quit"

#w "size 8; color red"

#w "goto 400 300 ; size 2 ; down ; circle 250"

for th =0 to 350 step 10
    cx =400 +250 *cos( th *3.14159265 /180)
    cy =300 +250 *sin( th *3.14159265 /180)
    call dottedLine 400, 300, cx, cy
next th

#w "flush"

scan
wait

sub dottedLine x1, y1,    x2, y2                            '   need atn2 and cos/sin here?
    dx      =x2 -x1
    dy      =y2 -y1
    L       =int( ( dx^2 +dy^2)^0.5)
    th      =atan2( dy, dx)
    count   =0

    for radius =0 to L step 8
        count =( count +1) mod 4
        if count =0 then #w "color red ; size 4" else #w "color 50 50 200 ; size 2"
        s0 =x1 +  radius       /L *dx
        t0 =y1 +  radius       /L *dy
        s1 =x1 +( radius +1)   /L *dx
        t1 =y1 +( radius +1)   /L *dy
        #w "line "; s0; " "; t0; " "; s1; " "; t1
    next radius
end sub

function atan2( y, x)
    pi =atn( 1) *4
    if x <>0 then arctan = atn( y /x)
    select case
        case x >0
            atan2 =arctan
        case y >=0 and x <0
            atan2 =pi +arctan
        case y <0 and x <0
            atan2 =arctan -pi
        case y >0 and x =0
            atan2 =pi /2
        case y <0 and x =0
            atan2 =pi /-2
    end select
end function

sub quit h$
    close #w
    end
end sub