createBulbs( )

The crcatcBulbs( ) method is a helper to init( ). It returns an Image of a stack of bulb images that can be used Lomask out a column of colored squares to make them look like lit lightbulbs. It is a littletricky, but quite elegant. I First, it allocates the right number of ints in an array to store the pixels. Then, it declares another array, which is a picture of a single bulb, represented by the numbers 0,1, and 2. The Osrepresent black, the Is transparent pixels, and the 2s represent the white highlight. Next, a short array is (bulb Color Look Up Table). This maps the 0, 1, and 2 just mentioned into bit pixel values. The is opaque black The high-order byte is alpha, or transparency. The OxOOcOcOcisOa fully transparent light gray, and the opaque white. The for loop through each pixel, loading the appropriate 0, 1, or 2 from bulb, based on the position in the column. This is achieved by use of the mod (%) operator. This value is then used to look up the color from . Given this nrray of pixels, createllulbst ) returns the output of crcatclmaget ), passing in a Memory image Source object prepared with the pixels we just constructed.

color( ) 

The colort ) method retLirnSthe color or the pixel at the Ayposition in the source imago as a Color object. Since this applet runs continuously, we decided not to simply create a new Color object each time a single bulb was painted. This would be abusive of the garbage-collected heap instead unique Color objects are stored in a hash table, The maximum number of Color objects in the hash table can be as much as the.width times the height of the source image, but in practice, is usually much less.

reCAPTCHA is required.

Share This