Java Reference
In-Depth Information
To generate a random number x , where 0 x < 1, use x = Math.random(); . For
example, multiplying by 3 and converting to an integer results in an integer that
is from 0 to 2.
2.
The file named “humphrey-img.txt” contained with the code for this topic holds
raw image data 3 of a Martian rock called “Humphrey” that was taken by the
Mars Exploration Rover Spirit. The format of this text file is as follows:
First line: single number indicating the height and width of the image (in this
case, 461).
Lines 2-462: A row of 461 numbers each separated by a space. Each number
represents a pixel in grayscale and ranges from 0 to 255 where 0 is black and 255
is white.
For example, the following data describes a 3 by 3 square where every pixel is
white except for a black line along the diagonal from the upper-left corner to the
bottom-right corner:
3
0 255 255
255 0 255
255 255 0
a. Write a program to read in the data from the file and display it in a JFrame
window. To draw a single pixel at coordinate (X,Y) use the drawLine method
where the start and endpoints are both (X,Y). For speed, the contents of the file
should be read into an array once and the array data used in the paint() method
to draw the image. The final image should appear similar to the following picture:
Image Credit: NASA/JPL
3 The original raw image data has been cropped and converted to a textual format for purposes of
this project.
Search WWH ::




Custom Search