
Teste en dessinant :
Code : Tout sélectionner
Structure vector2f
x.f
y.f
EndStructure
Procedure GenerateIntervalPoint( List in.vector2f(), List out.vector2f() , interval.l = 10 )
ClearList(out())
Protected size.l = ListSize(in())
; il manque le premier élément
AddElement(out())
SelectElement(in(),0)
out()\x = in()\x
out()\y =in()\y
For i = 1 To size-1
A.vector2f
B.vector2f
SelectElement(in(),i-1)
A\x = in()\x
A\y = in()\y
SelectElement(in(),i)
B\x = in()\x
B\y = in()\y
dist.d = Sqr((B\x-A\x)*(B\x-A\x) + (B\y-A\y)*(B\y-A\y))
If dist > interval And dist > 0
direction.vector2f
direction\x = B\x - A\x
direction\y = B\y - A\y
lenght.f = Sqr(direction\x * direction\x + direction\y * direction\y)
If lenght > 0
direction\x / lenght
direction\y / lenght
EndIf
insertNumber.l = (dist / interval)-1
Start.vector2f
Start\x = A\x
Start\y = A\y
AddElement(out())
out()\x = Start\x
out()\y = Start\y
For j = 0 To insertNumber - 1
AddElement(out())
offset.i = insertNumber + 1
out()\x = Start\x + (direction\x * interval)
out()\y = Start\y + (direction\y * interval)
Start\x + (direction\x * interval)
Start\y + (direction\y * interval)
Next
EndIf
Next
EndProcedure
NewList MesPoints.vector2f()
NewList MesPointsIntermediaires.vector2f()
;
; AddElement(MesPoints())
; MesPoints()\x = 10
; MesPoints()\y = 10
;
;
; AddElement(MesPoints())
; MesPoints()\x = 395
; MesPoints()\y = 127
;
;
; AddElement(MesPoints())
; MesPoints()\x = 682
; MesPoints()\y = 263
;
; AddElement(MesPoints())
; MesPoints()\x = 569
; MesPoints()\y = 241
;
; GenerateIntervalPoint( MesPoints(), MesPointsIntermediaires(), 20)
;
w = 1024
h= 768
OpenWindow(0, 0, 0, w,h, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0,0,0,w,h)
If StartDrawing(CanvasOutput(0))
ForEach MesPointsIntermediaires()
Circle(MesPointsIntermediaires()\x ,MesPointsIntermediaires()\y,4,0)
Next
StopDrawing()
EndIf
Repeat
Event = WaitWindowEvent()
EventGadget = EventGadget()
Select event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget
Case 0
If EventType() = #PB_EventType_LeftButtonDown
draw = 1
ElseIf EventType() = #PB_EventType_LeftButtonUp
draw = 0
ElseIf (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
If draw = 1
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
AddElement(MesPoints())
MesPoints()\x = x
MesPoints()\y = y
GenerateIntervalPoint( MesPoints(), MesPointsIntermediaires(), 20) ; je ne sais pas si c'est top de le générer à chaque tour de boucle,
; ce serait mieux de vider la liste MesPoints(), j'imagine (sauf le dernier élément)
If StartDrawing(CanvasOutput(0))
Box(0,0,w,h,RGBA(255,255,255,255))
ForEach MesPointsIntermediaires()
Circle(MesPointsIntermediaires()\x ,MesPointsIntermediaires()\y,4,0)
Next
StopDrawing()
EndIf
EndIf
EndIf
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow