Create a movie that has two filled rectangles that move by a random amount in x and y (< 5 pixels) each time. Make sure that they don’t go outside the picture.
What will be an ideal response?
```
/? ?
? Method t o r e t u r n a random amount added t o i < 5 b u t
? c h e c k i n g n o t t o e x c e e d t h e g i v e n max
? @param i t h e c u r r e n t v a l u e
? @param max t h e max f o r t h i s d i r e c t i o n ( x or y )
? @return i + some random amount < 5
?/
private i n t getRandomExtra ( in t i , i n t max)
{
i n t v a l u e = i + randNumGen . n e x t I n t ( 5 ) ;
i f ( v a l u e > max)
v a l u e = max ? 5 ;
return v a l u e ;
}
/? ?
? Method t o make a movie t h a t has a two r e c t a n g l e s moving
? around by a d d i n g a random amount l e s s tha n 5 p i x e l s
? @param d i r e c t o r y t h e d i r e c t o r y t o p u t t h e movie
? frames
?/
public void makeTwoRectangleRandMovie ( S t r i n g d i r e c t o r y )
{
int framesPerSec = 3 0 ;
P i c t u r e p = null ;
G r a p h i c s g = null ;
FrameSequencer f r a m e S e q u e n c e r =
new FrameSequencer ( d i r e c t o r y ) ;
// l o o p t h r o u g h t h e f i r s t s e c o n d
f o r ( i n t i = 0 ; i < f r a m e s P e r S e c ; i ++)
{
// draw a f i l l e d r e c t a n g l e
p = new P i c t u r e ( 6 4 0 , 4 8 0 ) ;
g = p . getGraphics ( ) ;
g . s e t C o l o r ( C o l o r .RED) ;
g . f i l l R e c t ( getRandomExtra ( i , 6 3 9 ) ,
getRandomExtra ( i , 4 7 9 )
,50 ,50);
g . s e t C o l o r ( C o l o r .BLUE ) ;
g . f i l l R e c t ( getRandomExtra ( i + 1 0 0 , 6 3 9 ) ,
getRandomExtra ( i , 4 7 9 ) ,
50 ,50);
// add frame t o s e q u e n c e r
f r a m e S e q u e n c e r . addFrame ( p ) ;
}
// p l a y t h e movie
frameSequencer . play ( framesPerSec ) ;
}
```
You might also like to view...
When the Insert Table command is used to insert a table into a document, the formatting of the ________ is applied to the table
A) paragraph below the table B) paragraph above the table C) page above the table D) page below the table
Effective control of access requires the ability to ensure that access is only granted to ____________________ people.
Fill in the blank(s) with the appropriate word(s).