Microsoft Small Basic

Program Listing: CFD075
h = 480 'height
w = 780 'width

GraphicsWindow.Show()
GraphicsWindow.Height = h
GraphicsWindow.Width = w

'Only download the image once
cupImage = ImageList.LoadImage("http://img708.imageshack.us/img708/4155/cupsombra.png")
cup1 = Shapes.AddImage(cupImage)
cup2 = Shapes.AddImage(cupImage)
cup3 = Shapes.AddImage(cupImage)

xPos1 = w/2 -150 'initial x position for cup1
xPos2 = w/2 'initial x position for cup2
xPos3 = w/2 + 150 'initial x position for cup3
yPos1 = h/2-50 'y position for all cups
yPos2 = yPos1
yPos3 = yPos1

Shapes.Move(cup1,xPos1,yPos1) 'inital position
Shapes.Move(cup2,xPos2,yPos2)
Shapes.Move(cup3,xPos3,yPos3)

Program.Delay(1000)

'Test swapping the using simple animation
xPos1 = w/2
xPos2 = w/2 + 150
xPos3 = w/2 -150
AnimateCups()

Program.Delay(1000)

Sub AnimateCups ' Animate to new positions in 1 sec
Shapes.Animate(cup1,xPos1,yPos1,1000)
Shapes.Animate(cup2,xPos2,yPos2,1000)
Shapes.Animate(cup3,xPos3,yPos3,1000)
Program.Delay(1000)
EndSub

'A more complex controlled movement (the new cup position, negative for down movement)
xNewPos1 = 1 'Move cup 1 to position 1 (going up)
xNewPos2 = -2 'Move cup 2 to position 2 (going down)
xNewPos3 = 3 'Move cup 3 to position 3 (going up)
MoveCups()
Program.Delay(1000)
xNewPos1 = 3 'Move cup 1 to position 3 (going up)
xNewPos2 = 1 'Move cup 2 to position 1 (going up)
xNewPos3 = -2 'Move cup 3 to position 2 (going down)
MoveCups()

Sub MoveCups
'Set start and end points for each cup
xStart1 = xPos1
xStart2 = xPos2
xStart3 = xPos3
xEnd1 = w/2 + 150*(Math.Abs(xNewPos1)-2)
xEnd2 = w/2 + 150*(Math.Abs(xNewPos2)-2)
xEnd3 = w/2 + 150*(Math.Abs(xNewPos3)-2)
For i = 1 To 100
'New X positions
xPos1 = xStart1 + i/100*(xEnd1-xStart1)
xPos2 = xStart2 + i/100*(xEnd2-xStart2)
xPos3 = xStart3 + i/100*(xEnd3-xStart3)
'New Y positions using a simple sine wave for the vertical movement
vertMove = 80*Math.Sin(i/100*Math.Pi) 'Vertical movement
yPos1 = h/2-50 - xNewPos1/Math.Abs(xNewPos1)*vertMove
yPos2 = h/2-50 - xNewPos2/Math.Abs(xNewPos2)*vertMove
yPos3 = h/2-50 - xNewPos3/Math.Abs(xNewPos3)*vertMove
'Move cups
Shapes.Move(cup1,xPos1,yPos1)
Shapes.Move(cup2,xPos2,yPos2)
Shapes.Move(cup3,xPos3,yPos3)
Program.Delay(10)
EndFor
'Update the final position
xPos1 = xEnd1
xPos2 = xEnd2
xPos3 = xEnd3
EndSub