Home Resources

 

Lessons from BOB : PART TWO

 

ANIMATING THE FACE

 

 

To animate the face, you will need to draw an image on the GLCD and then wait for a while – anything more than 50 msec and then draw a second image.

 

 EYE_DO_LOOP.png

Let’s just say we want the right eye to blink.  We first draw the whole face.  Then we draw the right eye close and wait for 500 msec.  We now draw the right eye open again.  This will give the illusion that the eye is blinking. Try the following code:

 CODE :

 

OS.GLCD.Init()

OS.GLCD.Fill(255)

 

'DRAW RIGHT EYE

DRAW_EYE(25, 70, True)

'DRAW LEFT EYE

DRAW_EYE(75, 70, True)

'DRAW MOUTH

DRAW_MOUTH(32, 30, 1)

Delay(1000) 'DELAY FOR 1 SEC

'CLOSE RIGHT EYE

DRAW_EYE(25, 70, False)

Delay(500) 'WAIT FOR A WHILE

'DRAW RIGHT EYE

DRAW_EYE(25, 70, True)

 

 

 

Most of the codes are from lesson one; the additional codes are the last 6 lines.

 

We can do the same for the mouth.  To make it look like the face is talking we will need to draw different positions of the mouth again and again.

 

To make things a little more interesting, we can make use of a random generator to randomly decide which mouth to draw. The RND function will return a random value every time it is called.  Check the ‘FIDE System Library’ documentation for details of the RND function.

 

 CODE :

 

 POS = RND(3)

 

 

The above code will randomly return a number from 0 to 2.  (Don’t forget to declare POS at the top of your code eg. Dim POS As Integer).

 

 images_SD.png

But, our mouth images for talking are positions 3, 4 and 5.  So we add 3 to get these values.

 

RND_GEN.png

 

 CODE :

 

 POS = RND(3) + 3

 

 

To draw the mouth repeatedly, we use DO LOOP.  Try out the code below.

 

 CODE :

 

Do

       POS = RND(3) + 3

       'DRAW MOUTH

       DRAW_MOUTH(32, 30, POS)

       Delay(300)

Loop

 

 

That is all that you will need to make the GLCD face blink and talk.

 

CODE :

 

Dim POS As Integer

 

'LESSON 2

Public Sub Main()

       OS.GLCD.Init()

       OS.GLCD.Fill(255)

      

       'DRAW RIGHT EYE

       DRAW_EYE(25, 70, True)

       'DRAW LEFT EYE

       DRAW_EYE(75, 70, True)

       'DRAW MOUTH

       DRAW_MOUTH(32, 30, 1)

      

       Delay(1000) 'DELAY FOR 1 SEC

       'CLOSE RIGHT EYE

       DRAW_EYE(25, 70, False)

      

       Delay(500) 'WAIT FOR A WHILE

      

       'DRAW RIGHT EYE

       DRAW_EYE(25, 70, True)

      

       Do

              POS = RND(3) + 3

              'DRAW MOUTH

              DRAW_MOUTH(32, 30, POS)

              Delay(300)

       Loop

End Sub

 


 


Don't understand certain parts? Try starting from Part One Here.

Continue to Part THREE >>>