Code: Select all
tX = 5
Dim Y(tX)
Y(0) = 100
Y(1) = 200
Y(2) = 30
Y(3) = 120
Y(4) = 300
Y(5) = 100
Procedure.d DegToRad(D.d)
ProcedureReturn D * #PI/180
EndProcedure
Procedure.f Interpolate(A.f, B.f, cX.f)
; a = 1st Number
; b = 2nd Number
; cX = Relationship (0 - 1)
ProcedureReturn b*cX + a*(1-cX)
EndProcedure
Procedure.f InterpolateSine(A.f, B.f, cX.f)
; a = 1st Number
; b = 2nd Number
; v = Relationship (0 - 1)
; "Stretch" cx to the correct range for Sin()
cX = cX * (180*#PI/180) + DegToRad(90)
; Pass cX to Sin() and compress the result to the
; correct range for Interpolate()
cX = 1 - ( Sin(cX) + 1 ) / 2
ProcedureReturn Interpolate(A, B, cX)
EndProcedure
Global pX, pY
Procedure LinePlotStart(X, Y)
pX = X
pY = Y
EndProcedure
Procedure LinePlot(X, Y, Col)
LineXY(pX, pY, X, Y, Col)
pX = X
pY = Y
EndProcedure
CreateImage(0, 512, 420)
StartDrawing(ImageOutput(0))
Box(0, 0, 512, 420, #White)
For X = 0 To tX
Circle(X*100, Y(X), 2, #Blue)
Next
LinePlotStart(0, Y(0))
For X = 0 To tX-1
For cX = 0 To 100
; Linear interpolation
Y = Interpolate(Y(X), Y(X+1), cX/100)
Plot(X*100+cX, Y, RGB(192, 192, 192))
; Sine interpolation with line plotting
Y = InterpolateSine(Y(X), Y(X+1), cX/100)
LinePlot(X*100+cX, Y, #Red)
Next
Next
StopDrawing()
OpenWindow(0, 0, 0, 512, 420, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ImageGadget(0, 0, 0, 0, 0, ImageID(0))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver