sas

Topic: Animation Control


      In this lesson we will consider some three projects involving animation.   Animation is caused by the motion of inanimate objects.

1. Project using Animation Control:

     The Animation control allows you to create buttons which display animations appropriate to the function perfomed by the computer.   For example, when a filecopy operation is perfomed, it will be appropriate when such a function is visually denoted by flying something  from the source to the destination.   In Windows 95, this function is denoted by pieces of paper flying from one folder to another folder.   Drag an animation control, a Common Dialog Control and two command buttons from the Toolbox.  The animation control will work only with silent avi files. Change the Caption property of command buttons as ‘play’ and ‘stop’ respectively and arrange them in the design window as shown in the figure 1.

Entering the code:

     Open the code window by doubleclicking the command button and enter the codes as shown in the figure 1a.

Private Sub Command1_Click()
CommonDialog1.ShowOpen
Animation1.Open CommonDialog1.filename
Animation1.AutoPlay = True
End Sub


Private Sub Command2_Click()
Animation1.Close
Animation1.Stop
End Sub

     Figure 1a

Running the Project:

     Select the Start button from the Run Menu.  The run mode window appears on the screen.   On clicking the play button, a file open dialog box appears.   You will find a number of avi files in the directory given by \program files\devstudio\vb\graphics\avi\ .   On selecting the file the animation display appears on the screen as shown in the figure 2.

a1

                             Figure 1

a2

                       Figure 2

2. Blinker Project:

     In this project we draw two picture boxes and two timers in the design form.   Two command buttons are included to start and stop the blinking operations.  The blinker design window looks as in the figure 3.   The codes for the timers, form and the command buttons are entered in the code window as shown in the figure 3a.   The project is saved and given the Run command.   The run mode window looks as in the figure 4.   On clicking the start button, the two picture boxes begin to blink one in red and another in blue  colors.   On clicking the stop button blinking stops.

Option Explicit
Private color1 As Long
Private color2 As Long

Private Sub Command1_Click()
Timer1.Interval = 500
Timer2.Interval = 300
Timer1.Enabled = True
Timer2.Enabled = True
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
Timer2.Enabled = False
End Sub

Private Sub Timer1_Timer()
If color1 = vbRed Then
color1 = vbGreen
Else
color1 = vbRed
End If
Picture1.BackColor = color1
End Sub

Private Sub Form_Load()
color1 = vbRed
color2 = vbBlue
Picture1.BackColor = color1
Picture2.BackColor = color2
End Sub

               Figure 3a

a3

                             Figure 3

a4

                            Figure 4

3. A Juggler Project:

     In this project a juggler will appear to be moving and at the same time juggling with three balls in his hands.   Drag 5 picture boxes and one timer in the form and make the design window look as shown in the figure 5.   Set the  timer interval property as 100.   Enter the codes as shown in the figure 5a.   Save the project and bring it to the run mode.   The run mode window looks as in the figure 6.   You can see the juggler moving and juggling.   In this project we load the picture file successively in 5 positions at short regular intervals.   This gives the illusion of motion.   

Dim i As Integer
Private Sub Form_Load()
i = 0
End Sub

Private Sub Timer1_Timer()
If i = 0 Then
Image5.Picture = LoadPicture
Image1.Picture = LoadPicture("c:\vbproj\juggler0.gif")
i = i + 1
ElseIf i = 1 Then
Image1.Picture = LoadPicture
Image2.Picture = LoadPicture("c:\vbproj\juggler1.gif")
i = i + 1
ElseIf i = 2 Then
Image2.Picture = LoadPicture
Image3.Picture = LoadPicture("c:\vbproj\juggler2.gif")
i = i + 1
ElseIf i = 3 Then
Image3.Picture = LoadPicture
Image4.Picture = LoadPicture("c:\vbproj\juggler3.gif")
i = i + 1
ElseIf i = 4 Then
Image4.Picture = LoadPicture
Image5.Picture = LoadPicture("c:\vbproj\juggler4.gif")
i = i + 1
Else
i = 0
End If
End Sub

Figure 5a                  

a5

                        Figure 5

a6
 
                                          Figure 6

Prev

 

 

 

 

 

 

 

 

 


footer back link


 

Error in my_thread_global_end(): 1 threads didn't exit