This function is not included in the SVG standard, yet it is very simple to implement.
Code: Select all
Structure Vector2:x.f:y.f:EndStructure
Procedure AddPathSpline(Array po.Vector2(1),Flags=0,roundness.f=0.5)
Protected n,i,close,coef.f=roundness/3
Protected.Vector2 b0,b1,b2,b3,c
n=ArraySize(po())+2
Dim p.Vector2(n)
If flags=#PB_Path_Relative:c\x=PathCursorX():c\y=PathCursorY():EndIf
For i=0 To n-2:p(i+1)\x=po(i)\x+c\x:p(i+1)\y=po(i)\y+c\y:Next
If p(n-1)\X = p(1)\X And p(n-1)\Y = p(1)\Y:close=1: p(0) = p(n-2): p(n) = p(2):Else:p(0) = p(2):p(n) = p(n-2):EndIf
MovePathCursor(p(1)\x,p(1)\y)
For i=1 To n-2
b0=p(i)
b3=p(i+1)
b1\x=b0\x+coef*(b3\x-p(i-1)\x)
b1\y=b0\y+coef*(b3\y-p(i-1)\y)
b2\x=b3\x-coef*(p(i+2)\x-b0\x)
b2\y=b3\y-coef*(p(i+2)\y-b0\y)
AddPathCurve(b1\x,b1\y, b2\x,b2\y, b3\x,b3\y)
Next
If close:ClosePath():EndIf
EndProcedure
OpenWindow(0, 0, 0, 600,600, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0,0,0,600,600)
Dim p.Vector2(8)
Repeat
b.f+0.04
For i=0 To 7:a.f=i*2*#PI/8
r=200+Sin(b+i*15)*50
p(i)\x=Cos(a)*r+300
p(i)\y=Sin(a)*r+300
Next
p(8)=p(0); to close the curve
StartVectorDrawing(CanvasVectorOutput(0))
VectorSourceColor($11ff6666)
FillVectorOutput()
addpathspline(p())
VectorSourceColor($ffffaaaa):FillPath(#PB_Path_Preserve)
VectorSourceColor($ff000000):StrokePath(4)
For i=0 To 7:AddPathCircle(p(i)\x,p(i)\y,4):Next
VectorSourceColor($ff0000ff):FillPath()
StopVectorDrawing()
Delay(32)
event=WindowEvent()
Until event=#PB_Event_CloseWindow Or event=#PB_Event_DeactivateWindow

