Author 
Topic: Dotted Lines (Read 396 times) 

HEOB
New Member
member is offline
Gender:
Posts: 18


Dotted Lines
« Thread started on: Dec 1^{st}, 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


Logged




tsh73
Board Moderator
member is offline
Anatoly (real name)
Gender:
Posts: 1684


Re: Dotted Lines
« Reply #1 on: Dec 1^{st}, 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=x2x1
dy=y2y1
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*(xx1)/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*(yy1)/dy
cmd$=cmd$; "set ";x;" ";y;";"
next
end if
dottedLine$=cmd$
end function


Logged

damned Dog in the Manger



tenochtitlanuk
Board Moderator
member is offline
Gender:
Posts: 1168


Re: Dotted Lines
« Reply #2 on: Dec 1^{st}, 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...
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


Logged




HEOB
New Member
member is offline
Gender:
Posts: 18


Re: Dotted Lines
« Reply #3 on: Dec 2^{nd}, 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!


Logged




tsh73
Board Moderator
member is offline
Anatoly (real name)
Gender:
Posts: 1684


Re: Dotted Lines
« Reply #4 on: Dec 2^{nd}, 2015, 02:21am » 

Here's line with 16bit mask, much like in QBasic. Try different masks. EDIT Code:mask = 65535 ' FFFF, ................ 2^161 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=x2x1
dy=y2y1
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*(xx1)/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*(yy1)/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 2^{nd}, 2015, 02:28am by tsh73 » 
Logged

damned Dog in the Manger



