Constructor and Description |
---|
Picture()
Constructs a picture with no image.
|
Picture(double width,
double height)
Constructs a picture with a given width and height.
|
Picture(int[][] grayLevels)
Constructs a picture from an array of gray levels.
|
Picture(java.lang.String source)
Constructs a picture from a given file or URL.
|
Modifier and Type | Method and Description |
---|---|
void |
draw()
Shows this picture on the canvas.
|
Color |
getColorAt(int i)
Gets the color of a pixel.
|
Color |
getColorAt(int x,
int y)
Gets the color of a pixel.
|
int[][] |
getGrayLevels()
Gets a two-dimensional array of the gray levels of all pixels
in this picture.
|
int |
getHeight()
Gets the height of this picture.
|
int |
getMaxX()
Gets the rightmost x-position of the shape.
|
int |
getMaxY()
Gets the bottommost y-position of the shape.
|
int |
getWidth()
Gets the width of this picture.
|
int |
getX()
Gets the leftmost x-position of the shape.
|
int |
getY()
Gets the topmost y-position of the shape.
|
void |
grow(double dw,
double dh)
Resizes this picture both horizontally and vertically.
|
void |
load(java.lang.String source)
Loads a new picture from a given file or URL.
|
void |
paintShape(java.awt.Graphics2D g2)
Draws this shape.
|
int |
pixels()
The number of pixels in this picture.
|
void |
setColorAt(int i,
Color color)
Sets the color of a pixel.
|
void |
setColorAt(int x,
int y,
Color color)
Sets the color of a pixel.
|
void |
tint(Color c)
Tints this picture with the given color.
|
java.lang.String |
toString()
Yields a description of this shape.
|
void |
translate(double dx,
double dy)
Moves this picture by a given amount.
|
void |
turn(int turns)
Turns this picture by a given number of 90 degree turns.
|
public Picture()
public Picture(double width, double height)
width
- the desired widthheight
- the desired heightpublic Picture(java.lang.String source)
source
- the filename or URLpublic Picture(int[][] grayLevels)
grayLevels
- an array of gray levels (between 0 and 255) for each pixelpublic void load(java.lang.String source)
source
- the filename or URLpublic int getX()
public int getY()
public int getMaxX()
public int getMaxY()
public int getWidth()
public int getHeight()
public int pixels()
public int[][] getGrayLevels()
public void tint(Color c)
c
- the color to tint withpublic void turn(int turns)
turns
- the number of times to turn to the rightpublic java.lang.String toString()
Shape
public Color getColorAt(int i)
i
- the pixel indexpublic void setColorAt(int i, Color color)
i
- the pixel indexcolor
- the new color for the pixelpublic Color getColorAt(int x, int y)
x
- the x-coordinate (column) of the pixely
- the y-coordinate (row) of the pixelpublic void setColorAt(int x, int y, Color color)
x
- the x-coordinate (column) of the pixely
- the y-coordinate (row) of the pixelcolor
- the color of the pixel at the given row and columnpublic void translate(double dx, double dy)
dx
- the amount by which to move in x-directiondy
- the amount by which to move in y-directionpublic void grow(double dw, double dh)
dw
- the amount by which to resize the width on each sidedh
- the amount by which to resize the height on each sidepublic void draw()
public void paintShape(java.awt.Graphics2D g2)
paintShape
in interface Shape
g2
- the graphics context