Tear( ) Java Help

Tear( )

The Tear:() method modifies the work_pixels array for the next cell. It draws the tear effect onto the work pixels. It draws the tear effect line by line. To draw one line, the method copies pixels from the old image pixels into the work_pixels array. It uses two counters, one that is an index into the work.pixels array, the destination, and one that references an index into the array of.pixels for the old billboard, the source. Both . counters are started at zero. ‘The destination counter is always incremented by one. The source counter, however, is incremented by a floating-point number that is always greater than one. When the loop is run until the destination Index is larger than the .width of the line, the result ~the source index growing faster than the destination index. The overall effect is the in the destination, only a number of pixels on the left side of the image will be copied from the source. The pixels taken from the source will skip some pixels, resultingin pixels taken from the source being evenly distributed across the line.

Each line of the cell frame will use a larger value for the floating-point number on ·the line above. This makes lines toward the bottom draw on fewer pixels for the tear effect than lines toward Use top. This method has one big optimization that it uses to get around the slow array Indexing in java. Whenever a element in an array is used, bounds checking is done to ensure that the index is within the bounds of the array. There is a performance hit . involved in this bounds checking. The standard Java class, System, provides a method that allows you to copy sections of arrays from one array to another almost as fast or as fast as copying one array clement into another. This method is used to speed up the creation lines within the cell frames.It only uses this method when the applet knows some of the source pixels will be adjacent to one another. If the applet skips at least every other pixel from the source image, then it will use the standard loop method x_incremental less than Indicates that less than 1.5 will be added to-the source index counter each time, and there will be a speed benefit from using the array copy method for a particular line.


  • Feel free to send us an inquiry, we will reply back in hours.


Posted on September 18, 2014 in The Dynamic Billboard Applet

Share the Story

About the Author

Back to Top