public class Pixel extends java.lang.Object implements java.lang.Comparable<Pixel>
Pixels are represented as three integral color components (red, green, and
blue) in the inclusive range [0, 255]. Lower values mean less color; higher
mean more. For example, new Pixel(255,255,255)
represents white,
new Pixel(0,0,0)
represents black, and new Pixel(0,255,0)
represents green.
This data structure is immutable. Once a Pixel
is created, it cannot
be modified.
Modifier and Type | Field and Description |
---|---|
static Pixel |
BLACK
The
Pixel representing the RGB color black. |
static Pixel |
BLUE
The
Pixel representing the RGB color blue. |
static Pixel |
GREEN
The
Pixel representing the RGB color green. |
static Pixel |
RED
The
Pixel representing the RGB color red. |
static Pixel |
WHITE
The
Pixel representing the RGB color white. |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Pixel o) |
int |
distance(Pixel px)
Determines the level of similarity between this pixel and another by
summing the absolute values of the differences between corresponding
components of the two pixels.
|
boolean |
equals(java.lang.Object other)
Checks whether this pixel has the same components as the given Object.
|
boolean |
equals(Pixel px)
Compares the RGB values of the current Pixel with another to check if
they are the same (and thus whether the two Pixels equal each other)
|
int |
getBlue()
Accessor for the blue component of the pixel.
|
int[] |
getComponents()
Accessor for the pixel's components as an array of 3 integers, where
index 0 is red, index 1 is green, and index 2 is blue.
|
int |
getGreen()
Accessor for the green component of the pixel.
|
int |
getRed()
Accessor for the red component of the pixel.
|
int |
hashCode() |
java.lang.String |
toString()
Returns a string representation of this pixel.
|
public static final Pixel BLACK
Pixel
representing the RGB color black.public static final Pixel BLUE
Pixel
representing the RGB color blue.public static final Pixel RED
Pixel
representing the RGB color red.public static final Pixel GREEN
Pixel
representing the RGB color green.public static final Pixel WHITE
Pixel
representing the RGB color white.public int getRed()
public int getGreen()
public int getBlue()
public int[] getComponents()
public int distance(Pixel px)
Math.abs
px
- the other pixel with which to comparepublic java.lang.String toString()
For example, RED.toString()
is "(255, 0, 0)"
Note: This function will allow you to print pixels in a readable format. This can be very helpful while debugging, and we highly encourage you to use print statements to aid your debugging throughout this assignment.
toString
in class java.lang.Object
public boolean equals(Pixel px)
px
- The pixel being compared with thispublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object