Page 1 of 1

API arrow lines (PB4)

Posted: Fri Feb 03, 2006 9:13 pm
by einander
Code updated For 5.20+

Code: Select all

#FIB=0.01745329   ; pi/180
#RAD=57.2957795 ; 180/ pi
#HeadCap=1      ;arrow head only
#TailCap=2         ;arrow tail only
#BothCaps=3      ;arrow head and tail

Procedure APILine(DC,x,y,x1,y1,Width,Color) 
    pen=CreatePen_(#PS_SOLID,Width,Color)  
    SelectObject_(DC,pen) 
   MoveToEx_(DC,x,y,0):LineTo_(DC,x1,y1) 
   DeleteObject_(pen) 
EndProcedure 

Procedure AngleEndPoint(x,y,Ang,LineLenght,*p.Point) 
    *p\x= x+LineLenght*Cos(Ang*#FIB)        
    *p\y= y+LineLenght*Sin(Ang*#FIB) 
EndProcedure

Procedure AngLine(DC,x,y,Ang.f,LineLenght,LineWidth,RGB) 
    x2 = x+LineLenght*Cos(Ang*#FIB)        
    y2 = y+LineLenght*Sin(Ang*#FIB)
    APILine(DC,x,y,x2 ,y2,LineWidth,RGB)
EndProcedure

Procedure GetANG(x1,y1,x2,y2) 
    a = x2-x1
    b = y2-y1 
    c.f = Sqr(a*a+b*b) 
    Ang = ACos(a/c)*#RAD
    If y1 < y2 : ProcedureReturn 360-Ang : EndIf 
    ProcedureReturn Ang 
EndProcedure

Procedure ArrowLine(DC,x,y,x1,y1,LineWidth,CapType,CapSize,RGB)
    APILine(DC,x,y,x1,y1,LineWidth,RGB)
    Angle=GetANG(x,y,x1,y1)
    If CapType=1 Or CapType=3  ; arrow head
        AngLine(DC,x,y,(340-Angle),CapSize,LineWidth,RGB)
        AngLine(DC,x,y,(380-Angle),CapSize,LineWidth,RGB)
    EndIf
    If CapType=2 Or CapType=3  ; arrow tail
        AngLine(DC,x1,y1,(340-Angle),CapSize,LineWidth,RGB)
        AngLine(DC,x1,y1,(380-Angle),CapSize,LineWidth,RGB)
    EndIf
EndProcedure 

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 hWnd = OpenWindow(0, 0, 0,0,0 ,"", #WS_OVERLAPPEDWINDOW | #WS_MAXIMIZE) 
_Drawing=StartDrawing(WindowOutput(0))  
;SetWindowColor(0,0)   ; if uncomment, drawing fails ***********************
Box(0,0,WindowWidth(0),WindowHeight(0),0)  ; this line replaces SetWindowColor()

xcenter=WindowWidth(0)/2
ycenter=WindowHeight(0)/2

;=====================================
LineWidth=3           ; here your settings 
LineLenght=100
CapSize=15 
CapType=#BothCaps  ; select here Head, Tail or both
;=====================================
; Test it
For i= 0 To 360 Step 20
    AngleEndPoint(xcenter,ycenter,i,200,@p.Point)   ; just for test - line positions
    AngleEndPoint(p\x,p\y,-i,LineLenght,@z.Point)
    ArrowLine(_drawing,p\x,p\y,z\x,z\y,linewidth,CapType,CapSize,Random($FFFFFF))
 Next

Repeat 
Until WindowEvent() = #PB_Event_CloseWindow  

Posted: Mon Feb 06, 2006 8:40 am
by blueznl
your tagline still claims 3.93 :-)

(so does mine, euh... :oops: )

Posted: Mon Feb 06, 2006 1:03 pm
by Berikco
blueznl wrote:your tagline still claims 3.93 :-)

(so does mine, euh... :oops: )
:lol:

Posted: Mon Feb 06, 2006 1:08 pm
by Dare2
lol, einander.

You give us arrows and you get shafted. :)

Posted: Tue Feb 07, 2006 11:29 am
by einander
Image

Posted: Tue Feb 07, 2006 12:30 pm
by Dare2
:D