API arrow lines (PB4)

Share your advanced PureBasic knowledge/code with the community.
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

API arrow lines (PB4)

Post 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  
Last edited by einander on Sun Mar 28, 2010 9:54 am, edited 1 time in total.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

your tagline still claims 3.93 :-)

(so does mine, euh... :oops: )
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

blueznl wrote:your tagline still claims 3.93 :-)

(so does mine, euh... :oops: )
:lol:
Last edited by Berikco on Mon Feb 06, 2006 1:26 pm, edited 1 time in total.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

lol, einander.

You give us arrows and you get shafted. :)
@}--`--,-- A rose by any other name ..
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Post by einander »

Image
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

:D
@}--`--,-- A rose by any other name ..
Post Reply