DrawVector2D() with arrow for PB4.40 Line() behaviour

Share your advanced PureBasic knowledge/code with the community.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

DrawVector2D() with arrow for PB4.40 Line() behaviour

Post by Psychophanta »

Code: Select all

Procedure DrawVector2D(CX.l,CY.l,X.l,Y.l,color.l=$CCCCCC,long.w=17,transv.w=5)
  Protected modc.f=Sqr(X*X+Y*Y),a1.l=-X*long/modc+Y*transv/modc,a2.l=-Y*long/modc-X*transv/modc,b1.l=-X*long/modc-Y*transv/modc,b2.l=-Y*long/modc+X*transv/modc
  If X=0:If Y=0:Plot(CX,CY,color):Else:Line(CX,CY,1,Y,color):EndIf:ElseIf Y=0:Line(CX,CY,X,1,color):Else:Line(CX,CY,X,Y,color):EndIf
  If a1=0:a1+1:EndIf:If a2=0:a2+1:EndIf:If b1=0:b1+1:EndIf:If b2=0:b2+1:EndIf
  Line(CX+X,CY+Y,a1,a2,color):Line(CX+X,CY+Y,b1,b2,color)
EndProcedure
Using LineXY():

Code: Select all

Procedure DrawVector2D(CX.f,CY.f,X.f,Y.f,color.l=$CCCCCC,long.w=17,transv.w=5)
  Protected modc.f=Sqr(X*X+Y*Y),BX.f=CX+X,BY.f=CY+Y
  LineXY(CX,CY,BX,BY,color):X/modc:Y/modc
  LineXY(BX,BY,BX-X*long+Y*transv,BY-Y*long-X*transv,color):LineXY(BX,BY,BX-X*long-Y*transv,BY-Y*long+X*transv,color)
EndProcedure
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;