Liberty BASIC Community Forum
« Dotted Lines »

Welcome Guest. Please Login or Register.
May 22nd, 2017, 10:37am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Dotted Lines  (Read 281 times)
HEOB
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 18
xx Dotted Lines
« Thread started on: Dec 1st, 2015, 09:27am »

How can I produce dotted lines at graphicbox?

#1.hrp "size 1; down; color red"
#1.hrp "place "; X(0); " "; Y(0)
for x= 0 to 360
#1.hrp "goto "; X(x); " "; Y(x)
next x
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1637
xx Re: Dotted Lines
« Reply #1 on: Dec 1st, 2015, 1:17pm »

There are probably API way of doing this

Or you can draw dots manually. like here
Code:
nomainwin
open "test" for graphics as #gr
#gr "trapclose [quit]"
#gr "down"

cx=150
cy=150
r=130
for a = 0 to 2*acs(-1) step acs(-1)/6
    x=cx+r*cos(a)
    y=cy+r*sin(a)
    #gr dottedLine$(cx,cy,x,y)
next

#gr "flush"
wait

[quit]
    close #gr
end

function dottedLine$(x1, y1, x2, y2)
    dx=x2-x1
    dy=y2-y1
    cmd$=""
    if abs(dx)>=abs(dy) then 'by x
        h = 2: if dx <0 then h = -2
        for x = x1 to x2 step h
            y=y1+dy*(x-x1)/dx
            cmd$=cmd$; "set ";x;" ";y;";"
        next
    else    'by y
        h = 2: if dy <0 then h = -2
        for y = y1 to y2 step h
            x=x1+dx*(y-y1)/dy
            cmd$=cmd$; "set ";x;" ";y;";"
        next
    end if
    dottedLine$=cmd$
end function


 
User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
tenochtitlanuk
Board Moderator

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1150
xx Re: Dotted Lines
« Reply #2 on: Dec 1st, 2015, 1:43pm »

(Ninja'd by Anatoly)
Here are two examples, each drawing a set of radial lines. One places characters (each with a rectangular backgrount, which makes a bit of a mess), the other draws using 'draw' repeatedly for a series of line segments. View the images at full size to see the detail..

Actually I can think of few occasions I've wanted such lines...

User Image

User Image

Code:
nomainwin
WindowWidth =800: WindowHeight =600

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

#w "trapclose quit"
#w "color 50 200 50"
#w "goto 400 300 ; down ; circle 250 ; size 2"
#w "font courier 10 bold"

for theta =0 to 360 step 5
    call dottedLine 400, 300, 400 +250 *cos( theta *3.14159265 /180), 300 +250 *sin( theta *3.14159265 /180)
    scan
next theta

#w "flush"
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 12
        count =( count +1) mod 2
        if count =1 then
            #w "color red"
        else
            #w "color 50 50 200"
        end if

        X0 =x1 +( radius /L *dx)' *sin( th)
        Y0 =y1 +( radius /L *dy)' *cos( th)
        #w "goto "; X0 -5; " "; Y0+5; " ; down"
        #w "\" +"@"
        #w "up"
    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 #h$
    end
end sub
 



Code:
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 4
        count =( count +1) mod 2
        if count =0 then #w "color red" else #w "color 50 50 200"
        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
 
User IP Logged

HEOB
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 18
xx Re: Dotted Lines
« Reply #3 on: Dec 2nd, 2015, 01:15am »

Thank you, tsh73 and tenochtitlanuc!

I understand that there is no direct command to produve dotted lines, I have to produce them "manually".

Anyway I am happy with "graphicbox" at LB.

Best greetings from Tyrol!
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1637
xx Re: Dotted Lines
« Reply #4 on: Dec 2nd, 2015, 02:21am »

Here's line with 16-bit mask, much like in QBasic.
Try different masks.
EDIT Code:
mask = 65535    ' FFFF, ................    2^16-1   solid line
'mask = 255     '00FF   ........
mask = 3855    '0F0F    ....    ....
'mask = 13107   '3333   ..  ..  ..  ..
'mask = 43690   'AAAA   . . . . . . . . 

Code:
print hexdec("FF")

nomainwin
open "test" for graphics as #gr
#gr "trapclose [quit]"
#gr "down"

cx=150
cy=150
r=130
mask = hexdec("FFFF")   'solid line
'mask =  hexdec("00FF")
mask =  hexdec("0F0F")
'mask =  hexdec("3333")
'mask =  hexdec("AAAA")
for a = 0 to 2*acs(-1) step acs(-1)/6
    x=cx+r*cos(a)
    y=cy+r*sin(a)
    #gr maskedLine$(cx,cy,x,y, mask)
next

#gr "flush"
wait

[quit]
    close #gr
end

function maskedLine$(x1, y1, x2, y2, mask)
    ' mask is 16 bit integer
    dx=x2-x1
    dy=y2-y1
    cmd$=""
    if abs(dx)>=abs(dy) then 'by x
        h = 1: if dx <0 then h = -1
        for x = x1 to x2 step h
            if mask and (2^maskpos) then
                y=y1+dy*(x-x1)/dx
                cmd$=cmd$; "set ";int(x);" ";int(y);";"
            end if
            maskpos= (maskpos+1) mod 16
        next
    else    'by y
        h = 1: if dy <0 then h = -1
        for y = y1 to y2 step h
            if mask and (2^maskpos) then
                x=x1+dx*(y-y1)/dy
                cmd$=cmd$; "set ";int(x);" ";int(y);";"
            end if
            maskpos= (maskpos+1) mod 16
        next
    end if
    maskedLine$=cmd$
end function
 
« Last Edit: Dec 2nd, 2015, 02:28am by tsh73 » User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14909
xx Re: Dotted Lines
« Reply #5 on: Dec 2nd, 2015, 05:47am »

If you are comfortable making calls to the operating system, you can create a dotted pen and select it into the device context of the graphicbox. It will then be used as the drawing pen for native commands.

http://lbpe.wikispaces.com/PensBrushes

The ways demonstrated in the previous responses are native LB commands and easier to use and understand if you do not have a background in calling Windows API.

If you are new to Liberty BASIC, you might be interested in a couple of online repositories of code, articles and examples.

http://lbpe.wikispaces.com/

http://rosettacode.org/wiki/Category:Liberty_BASIC
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls