javalib.worldimages
Interface WorldImage

All Superinterfaces:
Drawable, tester.ISame<WorldImage>
All Known Implementing Classes:
AImage, CircleImage, ColoredImage, Crop, EllipseImage, FreezeImage, FromFileImage, FromURLImage, LinearImage, OverlayImage, PolygonImage, RasterImage, RectangleImage, RectangularImage, TextImage

public interface WorldImage
extends tester.ISame<WorldImage>, Drawable

The API for an image.

Version:
Dec. 2, 2012
Author:
Stephen Bloch

Field Summary
static tester.Equivalence<WorldImage> LOOKS_SAME
          The equivalence operator that actually carries out pixel-for-pixel comparisons.
 
Method Summary
 WorldImage above(WorldImage... others)
          Concatenate two or more images vertically.
 WorldImage aboveCentered(WorldImage... others)
          Concatenate two or more images vertically.
 WorldImage beside(WorldImage... others)
          Concatenate two or more images horizontally.
 WorldImage besideCentered(WorldImage... others)
          Concatenate two or more images horizontally.
 WorldImage centerMoved(int x, int y)
          Produce the image with its center translated to the specified (x,y)
 WorldImage centerMoved(Posn xy)
          Produce the image with its center translated to the specified (x,y)
 WorldImage cropped(int left, int right, int top, int bottom)
          Get a new WorldImage by cropping this one to a rectangular window.
 void draw(Graphics2D g)
          Draw this image in the provided Graphics2D context.
 boolean equals(Object other)
          Is this the same as another WorldImage, as expression trees? Define this at every level that has instance variables.
 RasterImage frozen()
          Get a WorldImage just like this one, but with a memoized raster rendering.
 int getBottom()
          Produce the bottom of the bounding box.
 Posn getCenter()
          Find the approximate center of this image.
 int getHeight()
          Produce the height of this image
 int getLeft()
          Produce the left edge of the bounding box.
 Color getPixelColor(int x, int y)
          Get the color of a specified pixel of an image.
 int getRight()
          Produce the bottom of the bounding box.
 int getTop()
          Produce the top of the bounding box.
 int getWidth()
          Produce the width of this image
 int hashCode()
          Get a hash code for the WorldImage.
 WorldImage map(ImageMap map)
          Create a rectangular image pixel by pixel from an existing image.
 WorldImage map(ImageMap map, Object extra)
          Create a rectangular image pixel by pixel from an existing image.
 WorldImage moved(int dx, int dy)
          Produce the image translated by the given (dx, dy).
 WorldImage moved(Posn dxdy)
          Produce the image translated by the given (dx, dy).
 WorldImage normalized()
          Produce a "normalized" version of this image, with top-left corner at (0,0).
 WorldImage overlay(WorldImage... others)
          Overlay other images on this one, retaining their locations.
 WorldImage overlayCentered(WorldImage... others)
          Overlay other images on this one, ignoring location of all but centering them.
 WorldImage overlayXY(WorldImage front, int dx, int dy)
          Overlay another image on this one, retaining locations and translating the other image.
 WorldImage place(WorldImage front, int x, int y)
          Place another image onto this one, retaining the location of this one but translating the foreground so its center is at the specified location.
 WorldImage rotated(double degrees)
          Get a version of this image rotated by a specified number of degrees around (0,0).
 WorldImage rotated(int degrees)
          Get a version of this image rotated by a specified number of degrees around (0,0).
 WorldImage rotatedAround(double degrees, Posn anchor)
          Get a version of this image rotated by a specified number of degrees around a specified point.
 WorldImage rotatedAround(int degrees, Posn anchor)
          Get a version of this image rotated by a specified number of degrees around a specified point.
 WorldImage rotatedInPlace(double degrees)
          Get a version of this image rotated by a specified number of degrees around its center.
 WorldImage rotatedInPlace(int degrees)
          Get a version of this image rotated by a specified number of degrees around its center.
 boolean same(WorldImage other)
          Is this the same as another WorldImage, in the sense that they render the same?
 boolean save(String filename)
          Save a WorldImage to a .png file.
 WorldImage scaled(double factor)
          get a uniformly scaled copy of the image.
 WorldImage scaled(double xFactor, double yFactor)
          get a non-uniformly scaled copy of the image.
 void show()
          Display an image in a canvas.
 String toIndentedString(String indent)
          Produce a String that represents this image, indented by the given indent.
 String toString()
          Produce a String that represents this image.
 WorldImage xReflected()
          get a horizontally-reflected copy of the image.
 WorldImage yReflected()
          get a vertically-reflected copy of the image.
 
Methods inherited from interface javalib.worldimages.Drawable
makeImage
 

Field Detail

LOOKS_SAME

static final tester.Equivalence<WorldImage> LOOKS_SAME
The equivalence operator that actually carries out pixel-for-pixel comparisons.

Method Detail

above

WorldImage above(WorldImage... others)
Concatenate two or more images vertically. Retains x coords but moves the arguments vertically so each one's top edge aligns with the bottom of the previous one.

Parameters:
others - the images to concatenate below this, starting from the top
Returns:
a new WorldImage

aboveCentered

WorldImage aboveCentered(WorldImage... others)
Concatenate two or more images vertically. Ignores the locations of all images; matches the top edge of each with the bottom edge of the previous one, and centers horizontally.

Parameters:
others - the images to concatenate below this, starting from the top
Returns:
a WorldImage formed by concatenating this above the others

beside

WorldImage beside(WorldImage... others)
Concatenate two or more images horizontally. Retains y locations but moves arguments horizontally so each one's left edge aligns with the right edge of the previous one.

Parameters:
others - zero or more WorldImages
Returns:
a new WorldImage

besideCentered

WorldImage besideCentered(WorldImage... others)
Concatenate two or more images horizontally. Ignores the locations of both images; matches the left edge of each with the right edge of the previous one, and centers vertically.

Parameters:
others - the images to concatenate to the right of this, starting from the left
Returns:
a WorldImage formed by concatenating this to the left of the others

centerMoved

WorldImage centerMoved(int x,
                       int y)
Produce the image with its center translated to the specified (x,y)

Parameters:
x - the new x coordinate of the center
y - the new y coordinate of the center
Returns:
a new WorldImage, just like this one but translated.
Since:
Dec. 29, 2012

centerMoved

WorldImage centerMoved(Posn xy)
Produce the image with its center translated to the specified (x,y)

Parameters:
xy - the new center
Returns:
a new WorldImage, just like this one but translated.
Since:
Dec. 29, 2012

cropped

WorldImage cropped(int left,
                   int right,
                   int top,
                   int bottom)
Get a new WorldImage by cropping this one to a rectangular window. Each pixel in the result is in the same location as the corresponding pixel in the original was.

Parameters:
left -
top -
right -
bottom -
Returns:
a new WorldImage which is a rectangular portion of this one

draw

void draw(Graphics2D g)
Draw this image in the provided Graphics2D context.

Parameters:
g - the provided Graphics2D context

equals

boolean equals(Object other)
Is this the same as another WorldImage, as expression trees? Define this at every level that has instance variables.

Overrides:
equals in class Object
Parameters:
other - the object to compare with this
Returns:
true iff the images are isomorphic expression trees, with equal fields.

frozen

RasterImage frozen()
Get a WorldImage just like this one, but with a memoized raster rendering. To be used as a "hint" for large, complex images that are likely to be displayed many times before being modified.

Returns:
a RasterImage that memoizes the rendering of this image

getBottom

int getBottom()
Produce the bottom of the bounding box.

Returns:
the y coordinate of the bottom of the bounding box

getCenter

Posn getCenter()
Find the approximate center of this image.

Returns:
a Posn

getHeight

int getHeight()
Produce the height of this image

Returns:
the height of this image

getLeft

int getLeft()
Produce the left edge of the bounding box.

Returns:
the x coordinate of the left edge of the bounding box

getPixelColor

Color getPixelColor(int x,
                    int y)
Get the color of a specified pixel of an image.

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
the Color of the specified pixel.
Since:
Feb. 21, 2013

getRight

int getRight()
Produce the bottom of the bounding box.

Returns:
the x coordinate of the right edge of the bounding box

getTop

int getTop()
Produce the top of the bounding box.

Returns:
the y coordinate of the top of the bounding box

getWidth

int getWidth()
Produce the width of this image

Returns:
the width of this image

hashCode

int hashCode()
Get a hash code for the WorldImage. Needs to agree with equals(). In our case, "equals" means they're the same as expression trees.

Overrides:
hashCode in class Object

map

WorldImage map(ImageMap map)
Create a rectangular image pixel by pixel from an existing image. In this entrypoint, the "extra" parameter defaults to null.

Parameters:
map - an ImageMap encapsulating a function from Color to Color
Returns:
a new image the same size and shape as this
Since:
Dec. 28, 2012

map

WorldImage map(ImageMap map,
               Object extra)
Create a rectangular image pixel by pixel from an existing image.

Parameters:
map - an ImageMap encapsulating a function from Color to Color
extra - an arbitrary addtional argument to pass to the function
Returns:
a new image the same size and shape as this
Since:
Dec. 28, 2012

moved

WorldImage moved(int dx,
                 int dy)
Produce the image translated by the given (dx, dy).

Parameters:
dx - the horizontal offset
dy - the vertical offset
Returns:
a new WorldImage, just like this one but translated.

moved

WorldImage moved(Posn dxdy)
Produce the image translated by the given (dx, dy).

Parameters:
dxdy -
Returns:
a new WorldImage, just like this one but translated.

normalized

WorldImage normalized()
Produce a "normalized" version of this image, with top-left corner at (0,0).

Returns:
an image just like this (in fact it may BE this) whose top-left corner is at (0,0).

overlay

WorldImage overlay(WorldImage... others)
Overlay other images on this one, retaining their locations.

Parameters:
others - one or more images to overlay on this one.
Returns:
a new WorldImage

overlayCentered

WorldImage overlayCentered(WorldImage... others)
Overlay other images on this one, ignoring location of all but centering them.

Parameters:
others - one or more images to overlay on this one.
Returns:
a new WorldImage

overlayXY

WorldImage overlayXY(WorldImage front,
                     int dx,
                     int dy)
Overlay another image on this one, retaining locations and translating the other image.

Parameters:
front - the foreground image (to be translated)
dx - how much to move the foreground image horizontally
dy - how much to move the foreground image vertically
Returns:
a new WorldImage

place

WorldImage place(WorldImage front,
                 int x,
                 int y)
Place another image onto this one, retaining the location of this one but translating the foreground so its center is at the specified location. Crops to this image; that is, the result will not go beyond the bounds of the original image.

Parameters:
front - the foreground image (to be translated)
x - where to put the center of the foreground image
y - where to put the center of the foreground image
Returns:
a new WorldImage

rotated

WorldImage rotated(double degrees)
Get a version of this image rotated by a specified number of degrees around (0,0). This version of the method takes in a double.

Parameters:
degrees - a double, in this version
Returns:
a new WorldImage, just like this one but rotated.

rotated

WorldImage rotated(int degrees)
Get a version of this image rotated by a specified number of degrees around (0,0).

Parameters:
degrees -
Returns:
a new WorldImage, just like this one but rotated.

rotatedAround

WorldImage rotatedAround(double degrees,
                         Posn anchor)
Get a version of this image rotated by a specified number of degrees around a specified point.

Parameters:
degrees -
anchor - the fixpoint of the rotation
Returns:
a new WorldImage, just like this one but rotated.

rotatedAround

WorldImage rotatedAround(int degrees,
                         Posn anchor)
Get a version of this image rotated by a specified number of degrees around a specified point.

Parameters:
degrees -
anchor - the fixpoint of the rotation
Returns:
a new WorldImage, just like this one but rotated.

rotatedInPlace

WorldImage rotatedInPlace(double degrees)
Get a version of this image rotated by a specified number of degrees around its center.

Parameters:
degrees - a double, in this version.
Returns:
a new WorldImage, just like this one but rotated.

rotatedInPlace

WorldImage rotatedInPlace(int degrees)
Get a version of this image rotated by a specified number of degrees around its center.

Parameters:
degrees - an int, in this version
Returns:
a new WorldImage, just like this one but rotated.

same

boolean same(WorldImage other)
Is this the same as another WorldImage, in the sense that they render the same?

This is a weaker condition than equals(): it's quite possible for two distinct expression trees to render the same (e.g. two solid rectangles of the same color and width, stacked on top of one another, are same() as a single rectangle of that color and width and total height). Note also that same() does not imply substitutability: two distinct expression trees can be same(), but scaling them both up by a factor of 3 might not be same().

Specified by:
same in interface tester.ISame<WorldImage>
Parameters:
other - the WorldImage to compare with this
Returns:
true iff the images' renderings are pixel-for-pixel identical

save

boolean save(String filename)
Save a WorldImage to a .png file.

Parameters:
filename -
Returns:
true if the file was saved successfully.

scaled

WorldImage scaled(double factor)
get a uniformly scaled copy of the image.

Parameters:
factor -
Returns:
a new WorldImage which is factor times as large as this one.

scaled

WorldImage scaled(double xFactor,
                  double yFactor)
get a non-uniformly scaled copy of the image.

Parameters:
xFactor -
yFactor -
Returns:
a new WorldImage scaled by xFactor in the x dimension and yFactor in the y dimension

show

void show()
Display an image in a canvas.

Since:
Dec. 29, 2012

toIndentedString

String toIndentedString(String indent)
Produce a String that represents this image, indented by the given indent.

Define this in all concrete subclasses.

Convention: The result of toIndentedString() will neither begin nor end with a newline; the specified indent will immediately follow each internal newline.

Parameters:
indent - the given prefix representing the desired indentation
Returns:
the String representation of this image

toString

String toString()
Produce a String that represents this image.

Define this in all concrete subclasses.

Convention: The result of toString() will neither begin nor end with a newline, although there may be newlines in the middle.

Overrides:
toString in class Object
Returns:
the String representation of this image
Since:
Dec. 2, 2012

xReflected

WorldImage xReflected()
get a horizontally-reflected copy of the image.

Returns:
a new WorldImage just like this one but reflected.

yReflected

WorldImage yReflected()
get a vertically-reflected copy of the image.

Returns:
a new WorldImage just like this one but reflected.