I would like to know How I can use interpolation (cubic, catmull, bezier..) to "smooth" the line with a 2D painting (it's the same for a game, using sprite to create some ribbon effect for exemple).
Here the code (modified from the canvas example) :
Code: Select all
#IMAGE_Content =0
Enumeration
#GADGET_Canvas
#GADGET_Brush
#GADGET_Clear
EndEnumeration
Global Pas = 2,MouseX_Old,MouseY_Old
; Draw the mouse action result depending on the currently selected mode and event type
Macro point_distance(x1,y1,x2,y2)
Int(Sqr((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)) )
EndMacro
Macro point_direction(x1,y1,x2,y2)
ATan2((y2- y1),(x2- x1))
EndMacro
Procedure DrawBrush(x1,y1)
x2 = MouseX_Old
y2 = MouseY_Old
flech = point_distance(x1,y1,x2,y2)
d.d = point_direction(x1,y1,x2,y2)
For i = 1 To flech
i+pas
x_result = x1 + Sin(d) *i
y_result = y1 + Cos(d) *i
Circle(x_result,y_result,3,0)
;DrawImage(ImageID(#IMAGE_Brush),x_result-brush\size/2,y_result-brush\size/2)
Next i
EndProcedure
Procedure DrawAction(x, y, EventType)
If StartDrawing(CanvasOutput(#GADGET_Canvas))
If EventType = #PB_EventType_LeftButtonDown Or EventType = #PB_EventType_MouseMove
DrawBrush(x,y)
EndIf
StopDrawing()
EndIf
EndProcedure
CreateImage(#IMAGE_Content, 380, 380, 24)
If OpenWindow(0, 0, 0, 800, 600, "Interpolation", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(#GADGET_Canvas, 10, 10, WindowWidth(0)-80, WindowHeight(0)-20, #PB_Canvas_ClipMouse)
ButtonGadget(#GADGET_Clear, WindowWidth(0)-60, 100, 50, 25, "Clear")
SetGadgetAttribute(#GADGET_Canvas, #PB_Canvas_Cursor, #PB_Cursor_Cross)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case #GADGET_Canvas
X = GetGadgetAttribute(#GADGET_Canvas, #PB_Canvas_MouseX)
Y = GetGadgetAttribute(#GADGET_Canvas, #PB_Canvas_MouseY)
Type = EventType()
Select EventType()
Case #PB_EventType_LeftButtonDown
If StartDrawing(ImageOutput(#IMAGE_Content))
DrawImage(GetGadgetAttribute(#GADGET_Canvas, #PB_Canvas_Image), 0, 0)
StopDrawing()
EndIf
MouseY_Old = y
MouseX_Old = x
DrawAction(X, Y, EventType())
Case #PB_EventType_LeftButtonUp
DrawAction(X, Y, EventType())
Case #PB_EventType_MouseMove
If GetGadgetAttribute(#GADGET_Canvas, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton
DrawAction(X, Y, EventType())
MouseY_Old = y
MouseX_Old = x
EndIf
EndSelect
Case #GADGET_Clear
If StartDrawing(CanvasOutput(#GADGET_Canvas))
Box(0, 0, GadgetWidth(#GADGET_Canvas), GadgetHeight(#GADGET_Canvas), $FFFFFF)
StopDrawing()
EndIf
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
If you have an idea, it would be very great

Thank you.
EDIT :
I have the left Result, and I would like to have the right result for example :
