Well everything is in the title !

Nothing really serious, the code could be much better written and it's not particularly interesting, graphically speaking, but I just wanted to play with Interpolation.

( Interpolation discovery has been an illumination for me :) it's awesome all you can do with this simple concept ! )

Code: Select all

`Const MAX_PNT = 20`

Randomize timer

Type PntType

as single x,y

End Type

Type ShapeType

as integer NbPoints

as PntType Center

as PntType V

as PntType Pnt0(MAX_PNT)

as PntType Pnt(MAX_PNT)

End Type

Sub InterpolateShape(ByRef S1 as ShapeType, Byref S2 as ShapeType, ByVal t as single)

Dim as integer dX,dY

If S1.nbPoints<>S2.NbPoints then exit sub

For i as integer = 1 to S1.NbPoints

dX = S2.Pnt0(i).x - S1.Pnt0(i).x

dY = S2.Pnt0(i).y - S1.Pnt0(i).y

S1.Pnt(i).x = S1.Pnt0(i).x + t*dX

S1.Pnt(i).y = S1.Pnt0(i).y + t*Dy

next

End sub

Sub Clip(S as ShapeType)

For i as integer = 1 to S.NbPoints

If S.Center.x+S.pnt(i).x>320 or S.Center.x+S.pnt(i).x<0 then

S.V.X*=-1

S.Center.x+=S.v.x

end if

If S.Center.y+S.pnt(i).y>240 or S.Center.y+S.pnt(i).y<0 then

S.V.Y*=-1

S.Center.y+=S.v.y

end if

next

End sub

Sub RecallShape(S as ShapeType)

For i as integer = 1 to S.NbPoints-1

S.pnt(i) = S.pnt0(i)

next

End Sub

Sub RenderShape(Byref S as ShapeType,t as single)

For i as integer = 1 to S.NbPoints-1

Line(S.Center.x+S.Pnt(i).x,S.Center.y+S.Pnt(i).y)-(S.Center.x+S.Pnt(i+1).x,S.Center.y+S.Pnt(i+1).y),rgb(t*250,100+150*t,200-100*t)

next

Line(S.Center.x+S.Pnt(S.NbPoints).x,S.Center.y+S.Pnt(S.NbPoints).y)-(S.Center.x+S.Pnt(1).x,S.Center.y+S.Pnt(1).y),rgb(t*250,100+150*t,200-100*t)

Paint(S.Center.X,S.Center.Y),rgb(t*250,100+150*t,200-100*t)

End sub

Screenres 320,240,32,2

Dim as ShapeType Shape1, Shape2

Shape1.NbPoints = 8

Shape2.NbPoints = 8

Shape1.V=type(-.5+rnd/2,-.5+rnd/2)

Shape1.Center = type(150,150)

Shape2.Center = type(150,150)

Shape1.Pnt0(1) = type(-50,-50)

Shape1.Pnt0(2) = type(0,-50)

Shape1.Pnt0(3) = type(50,-50)

Shape1.Pnt0(4) = type(50,0)

Shape1.Pnt0(5) = type(50,50)

Shape1.Pnt0(6) = type(0,50)

Shape1.Pnt0(7) = type(-50,50)

Shape1.Pnt0(8) = type(-50,0)

For i as integer = 1 to 8

Shape2.Pnt0(9-i) = Type(50*cos(i*(6.28/8)+3*3.14/2),50*sin(i*(6.28/8)-3*3.14/2))

next

dim as single t,sign=1

Do : screenlock : cls

Shape1.Center.x+=Shape1.v.x

Shape1.Center.y+=Shape1.v.y

clip Shape1

InterpolateShape(Shape1,Shape2,t)

RenderShape Shape1,t

t+=.0008*sign : if t>=1 or t<=0 then sign*=-1

Screenunlock : sleep 1,1

Loop until multikey(&h01)