this example show you how to interpolate between some points
for painting a spline curve.
http://www.mvps.org/directx/articles/catmull/
http://de.wikipedia.org/wiki/Catmull-Rom_Spline#Catmull-Rom-Spline
rem
rem AGK Application 1.08
rem
//Catmull-Rom Splines
//M.Rauch 31.12.2012
//http://www.mvps.org/directx/articles/catmull/
//Kurve malen
//um einen Abschnitt zu malen brauchen wir 4 Punkte 0,1,2,3
//mit dem Parameter t=0 bis t=1 wird NUR die Strecke zwischen Punkt 1 und Punkt 2 gemalt
type TPoint
x#
y#
endtype
PT as TPoint
P0 as TPoint
P1 as TPoint
P2 as TPoint
P3 as TPoint
imgdot=loadimage("Dot.png") //<<<< a filled white circle i made with gimp with transparent background
sprdot=CreateSprite(imgdot)
SetSpriteSize(sprdot,4,4)
setspriteoffset(sprdot,2,2)
// my 4 Points
P0.x#=0
P0.y#=50
P1.x#=25
P1.y#=75
P2.x#=75
P2.y#=50
P3.x#=100
P3.y#=75
EnableClearColor( 0 ) //we use a fullscreen background , we don't need clear each frame
clearscreen()
//------------------------------------------- Draw between Point 1 to 2 , 0 to 1 , 2 to 3
// remember t is between 2 & 3 Parameter
SetSpriteColor(sprdot,255,255,0,255) // Yellow
// 3 Parts
//middle
for t#=0.0 to 1.0 step 0.01
PT=CurvePos(P0,P1,P2,P3,t#)
SetSpritePositionbyoffset(sprdot,PT.x#,PT.y#)
DrawSprite(sprdot)
next
//beginning
for t#=0.0 to 1.0 step 0.01
PT=CurvePos(P0,P0,P1,P2,t#)
SetSpritePositionbyoffset(sprdot,PT.x#,PT.y#)
DrawSprite(sprdot)
next
//end
for t#=0.0 to 1.0 step 0.01
PT=CurvePos(P1,P2,P3,P3,t#)
SetSpritePositionbyoffset(sprdot,PT.x#,PT.y#)
DrawSprite(sprdot)
next
//------------------------------------------- Plot my 4 Points (Dots)
SetSpriteColor(sprdot, 255,0,0,255) //Red
SetSpritePositionbyoffset(sprdot,P0.x#,P0.y#)
DrawSprite(sprdot)
SetSpritePositionbyoffset(sprdot,P1.x#,P1.y#)
DrawSprite(sprdot)
SetSpritePositionbyoffset(sprdot,P2.x#,P2.y#)
DrawSprite(sprdot)
SetSpritePositionbyoffset(sprdot,P3.x#,P3.y#)
DrawSprite(sprdot)
//-------------------------------------------
deletesprite(sprdot)
//Make a Screenshot as Background Sprite
imgbg=GetImage(0,0,100,100)
sprbg=createsprite(imgbg)
setspritesize(sprbg,100,100)
do
Sync()
loop
function CurvePos(P0 as TPoint,P1 as TPoint,P2 as TPoint,P3 as TPoint,t#)
//MR 31.12.2012
//t# 0.0 to 1.0 is the position between P1 and P2
PT as TPoint
PT.x# = 0.5 * ( (2.0 * P1.x#) + (-P0.x# + P2.x#) * t# + (2.0*P0.x# - 5.0*P1.x# + 4.0*P2.x# - P3.x#) * t#^2.0 + (-P0.x# + 3.0*P1.x#- 3.0*P2.x# + P3.x#) * t#^3.0 )
PT.y# = 0.5 * ( (2.0 * P1.y#) + (-P0.y# + P2.y#) * t# + (2.0*P0.y# - 5.0*P1.y# + 4.0*P2.y# - P3.y#) * t#^2.0 + (-P0.y# + 3.0*P1.y#- 3.0*P2.y# + P3.y#) * t#^3.0 )
//... 3D use the same with .z#
endfunction PT