|
Post by regoroxford on Nov 17, 2022 22:37:31 GMT -5
I have met with limited success. Ideally there is a .DLL to do the job. I have tried to use the slope to calculate radians and degrees and then #handle, "turn degees" and #1,"go ";distance with pen "up" and "down"..... With LB 4.5.1 I am experiencing a difference between LB instructions and reality. For example #1, "line x1 y1 x2 y2" needs to be #1, "Line ";x1;" ";y1;" ";x2;" ";y2 I have a large LB program for drawing line figures with colors and exact placement of new figure and lines by finding the closest corner or line end or figure center to reference. Drawing a dashed line from x1 y1 x2 y2 at any slope has stumped me. My current effort is not presentable at the moment.
|
|
|
Post by tsh73 on Nov 18, 2022 1:26:03 GMT -5
Have a look
nomainwin global markDashStart markDashStart = 1
open "test" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down"
#gr "home" #gr "posxy cx cy" '#gr "circle 20" '#gr "go 10"
x1=30 y1=30
x2=270 y2=140
sz=10 'dash size
#gr "color red" #gr "place ";x1;" ";y1 #gr "circle 10" #gr "place ";x2;" ";y2 #gr "circle 10"
#gr "color black" '#gr "line ";x1;" ";y1;" ";x2;" ";y2 call dashLine x1,y1,x2,y2, sz
pi = acs(-1) 'print pi r=120 markDashStart = 0 for i = 0 to 11 a=i/12*2*pi x=cx+r*cos(a) y=cy+r*sin(a) 'print i, a, y, r, r*sin(a) #gr "color black" call dashLine cx,cy,x,y, 3
#gr "color red" #gr "place ";x;" ";y #gr "circle 5"
next #gr "flush"
wait
sub dashLine x1,y1,x2,y2, sz d=sqr((x2-x1)^2+(y2-y1)^2) n=int(d/(2*sz)) for i = 0 to n-1 t=i/n: t2=(i+.5)/n xx1=int(x1+(x2-x1)*t) yy1=int(y1+(y2-y1)*t) xx2=int(x1+(x2-x1)*t2) yy2=int(y1+(y2-y1)*t2) if markDashStart then #gr "place ";xx1;" ";yy1 #gr "circle 8" end if #gr "line ";xx1;" ";yy1;" ";xx2;" ";yy2 next #gr "set ";x2;" ";y2 'last point? end sub [quit] close #gr end
|
|
|
Post by tenochtitlanuk on Nov 18, 2022 5:20:20 GMT -5
You might like to look at my page on drawing lines at www.diga.me.uk/bresenham.htmlI've used the Bresenham method ( see Rosetta Code) to draw dashed lines, dotted lines, and lines whose colour or width changes along their length or as a function of distance from start point.
|
|
|
Post by regoroxford on Nov 18, 2022 6:58:05 GMT -5
That should be more than adequate to help me draw dashed lines today. The reverse engineering necessary will be key to understanding. Thanks
|
|
|
Post by Walt Decker on Nov 18, 2022 9:14:09 GMT -5
Polar degrees can be found HEREDRAW DASHED LINE FROM X1, Y1 TO X2, Y2 ' PS.SOLID = 0 PS.DASH = 1 'SEE .[GRAFIX_1O1.RTF,"CreatePen"]. HS.DIAGCROSS = 5 'SEE .[GRAFIX_1O1.RTF,"CreateHatchBrush"].
FIREBRICK = HEXDEC("&H2222B2")
PenHndl = 0 OldPen = 0 DrawDc = 0
GfxHndl = HWND(#DMO.GFX) '<--- handle to gfx box
CALLDLL #user32, "GetDC", GfxHndl AS ULONG, DrawDc AS ULONG '<--- handle to device
CALLDLL #gdi32, "CreatePen", PS.DASH AS LONG, 2 AS LONG, FIREBRICK AS ULONG, _ PenHndl AS ULONG '<--- create the pen '<===== ATTACH THE PEN FOR DRAWING ==========================> CALLDLL #gdi32, "SelectObject", DrawDc AS ULONG, PenHndl AS ULONG, OldPen AS ULONG
CALLDLL #gdi32, "MoveToEx", DrawDc AS ULONG, X1 AS LONG, Y1 AS LONG, 0 AS LONG, _ RetVal AS VOID '<--- move to line start
'<================= DRAW TO LINE END ==================> CALLDLL #gdi32, "LineTo", DrawDc AS ULONG, X2 AS LONG, Y2 AS LONG, RetVal AS VOID
'<================= DETACH PEN ======================> CALLDLL #gdi32, "SelectObject, DrawDc AS ULONG, OldPen AS ULONG, RetVal AS VOID
'<================ RELEASE DEVICE ===================> CALLDLL #user32, "ReleaseDC", GfxHndl AS ULONG, DrawDc AS ULONG, RetVal AS VOID
'<=============== THIS MUST BE DONE TO MAKE IMAGE STICK ==============> '<======= "BMPTAG" CAN BE ANY NAME YOU WANT, E.G. LINEFROM ===========>
PRINT #DMO.GFX, "GETBMP BMPTAG 0 0 ";GfxWide;" ";GfxHigh '<--- get image PRINT #DMO.GFX, "DRAWBMP BMPTAG 0 0" '<--- redraw image PRINT #DMO.GFX, "FLUSH" '<--- make it stick PRINT #DMO.GFX, "DISCARD" '<--- remove meta-file '
More info concerning API can be found in the General Discussion thread topic "Things you don't want to know about the win API"
|
|
|
Post by regoroxford on Nov 18, 2022 10:03:40 GMT -5
nomainwin open "test" for graphics_FS as #1 #1, "trapclose [quit]" #1, "down"
x1=130 y1=130 x2=870 y2=940
sz=40 'dash size #1, "color red" : #1,"size 6" #1,"set ";x1;" "; y1 'setup red targets #1,"set ";x2;" "; y2 #1, "size 1" #1, "color black"
open "c:\lbdrawings\dashedlinedata" for output as #3 'record x & y & T & T2 data call dashLine x1,y1,x2,y2, sz wait
sub dashLine x1,y1,x2,y2, sz d=sqr((x2-x1)^2+(y2-y1)^2) 'pixels between pt1 & pt2
n=int(d/(2*sz)) 'length in pixels of (dash + no dash) (wave length)
for i = 0 to n-1 'step thru number of wavelengths
t=i/n 't starts small and reaches almost 1
t2=(i+.5)/n '
xx1=int(x1+(x2-x1)*t) 'xx1: x1 is increased by quantity of (x2-x1) * t
yy1=int(y1+(y2-y1)*t) 'yy1: y1 is increased proportionally * t
xx2=int(x1+(x2-x1)*t2) 'xx2: x1 is increased an EVEN larger amt *t2
yy2=int(y1+(y2-y1)*t2) 'yy2: y1 ...
print #3,xx1;" ";yy1;" ";xx2;" ";yy2;" ";t;" ";t2 'recording x & y data
#1, "line ";xx1;" ";yy1;" ";xx2;" ";yy2 'draw one line segment
next i #1, "line ";xx2;" ";yy2;" ";x2;" ";y2 'draw one line segment end sub [quit] close #1 close #3
end
Your code was easy to modify to get dashed line I needed for my program. I'm still working to think about inching along the hypotenuse the way you did. I conceived of the idea but did not get there.
|
|