Graphics Programming using Allegro

Practice Test

A Bouncing-Ball Animation

Published:  September 8, 2008
By Richard G. Baldwin

File: Allegro00125PracticeTest


Questions

1.  True or False:  The Allegro function named set_color_depth is used to establish the number of bits that will be used to represent a color.

Answer and Explanation

2.  True or False:  A typical way to generate pseudo-random numbers in a determined range using the function named rand is to use the modulo of the returned value by the range span and add the initial value of the range.

Answer and Explanation

3.  True or False:  Successive calls to the rand function shown below will generate an approximately uniformly distributed series of pseudo-random numbers ranging from 0 through 3 inclusive.

  dir = rand() % 4 + 1;

Answer and Explanation

4.  True or False:  For every different seed value used in a call to the function named srand, the pseudo-random number generator can be expected to generate a different succession of results in the subsequent calls to rand.

Answer and Explanation

5.  True or False:  The pseudo-random number generator function named rand can be initialized by calling the function named srand and passing an initialization seed as a parameter.  Two different initializations with different seed values instructs the pseudo-random generator to generate the same succession of results for the subsequent calls to rand in both cases.

Answer and Explanation

6.  True or False:  The value returned by calling the function named time is normally suitable for use as a parameter to the srand function, provided that you don't call the srand function more than once per second.

Answer and Explanation

7.  True or False:  The purpose of an animation loop is typically to cause the program to loop continuously, performing a sequence of actions, until the user performs some action (such as pressing the Esc key) to terminate the loop.

Answer and Explanation

8.  True or False:  Assume that you are writing an animation that has a green ball moving across a solid black background.  Assume that the current location of the ball is given by oldX and oldY.  Assume that the new location of the ball is given by x and y.  The following code can be used to erase the ball from its current location and draw it in its new location.

circlefill(screen,oldX,oldY,radius,makecol(255,255,255));
circlefill(screen,x,y,radius,makecol( 128, 255, 0));

Answer and Explanation

9.  True or False:  Assume that you are writing an animation that has a green ball moving across a solid black background.  Assume that the current location of the ball is given by oldX and oldY.  Assume that the new location of the ball is given by x and y.  The following code can be used to erase the ball from its current location and draw it in its new location.

circlefill(screen,oldX,oldY,radius,makecol(0,0,0));
circlefill(screen,x,y,radius,makecol( 128, 255, 0));

Answer and Explanation



Copyright 2008, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java, C#, and XML. In addition to the many platform and/or language independent benefits of Java and C# applications, he believes that a combination of Java, C#, and XML will become the primary driving force in the delivery of structured information on the Web.

Richard has participated in numerous consulting projects and he frequently provides onsite training at the high-tech companies located in and around Austin, Texas.  He is the author of Baldwin's Programming Tutorials, which have gained a worldwide following among experienced and aspiring programmers. He has also published articles in JavaPro magazine.

In addition to his programming expertise, Richard has many years of practical experience in Digital Signal Processing (DSP).  His first job after he earned his Bachelor's degree was doing DSP in the Seismic Research Department of Texas Instruments.  (TI is still a world leader in DSP.)  In the following years, he applied his programming and DSP expertise to other interesting areas including sonar and underwater acoustics.

Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.

Baldwin@DickBaldwin.com

 


Answers and Explanations


Answer 9

True

Explanation 9

Back to Question 9


Answer 8

False - this would draw a white ball in the current location instead of erasing it.

Explanation 8

Back to Question 8


Answer 7

True

Explanation 7

Back to Question 7


Answer 6

True

Explanation 6

Back to Question 6


Answer 5

False - different sequences will be generated for different seed values

Explanation 5

Back to Question 5


Answer 4

True

Explanation 4

Back to Question 4


Answer 3

False - numbers will be in the range from 1 through 4 inclusive

Explanation 3

Back to Question 3


 

Answer 2

True

Explanation 2

Back to Question 2


Answer 1

True

Explanation 1

Back to Question 1


Copyright 2008, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java, C#, and XML. In addition to the many platform and/or language independent benefits of Java and C# applications, he believes that a combination of Java, C#, and XML will become the primary driving force in the delivery of structured information on the Web.

Richard has participated in numerous consulting projects and he frequently provides onsite training at the high-tech companies located in and around Austin, Texas.  He is the author of Baldwin's Programming Tutorials, which have gained a worldwide following among experienced and aspiring programmers. He has also published articles in JavaPro magazine.

In addition to his programming expertise, Richard has many years of practical experience in Digital Signal Processing (DSP).  His first job after he earned his Bachelor's degree was doing DSP in the Seismic Research Department of Texas Instruments.  (TI is still a world leader in DSP.)  In the following years, he applied his programming and DSP expertise to other interesting areas including sonar and underwater acoustics.

Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.

Baldwin@DickBaldwin.com

 

-end-