javalib.worldimages
Class AImage

java.lang.Object
  extended by javalib.worldimages.AImage
All Implemented Interfaces:
Drawable, WorldImage, tester.ISame<WorldImage>
Direct Known Subclasses:
ColoredImage, Crop, LinearImage, OverlayImage, RasterImage

public abstract class AImage
extends Object
implements WorldImage

The most important class in the worldimages package.

Most of the methods you'll call on images live here: makeCircle, makeFromURL, above, scaled, rotated, place, show, etc.

All images have a bounding box, which you can get with getLeft(), getTop(), getRight(), getBottom().

Most of this class is factory methods for various kinds of images. In many case, a factory method has to be written six times, with different combinations of Color and Mode arguments. Sometimes Java really annoys me....

Convention: the "makeWhatever" methods in AImage are public, and there's a version for each reasonable combination of missing parameters; these simply call the corresponding "make" method in the appropriate class. The "make" methods in each concrete class are package-private, and there's a version for each reasonable combination of missing parameters; these all call the constructor. The constructor (in most cases) is protected, and there's only one version.

Version:
Dec. 26, 2012
Author:
Stephen Bloch

Field Summary
 
Fields inherited from interface javalib.worldimages.WorldImage
LOOKS_SAME
 
Constructor Summary
AImage()
           
 
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.
static WorldImage build(int width, int height, ImageBuilder builder)
          Build a rectangular image pixel by pixel, with no "extra" information.
static WorldImage build(int width, int height, ImageBuilder builder, Object extra)
          Build a rectangular image pixel by pixel.
 WorldImage centerMoved(int x, int y)
          Produce a copy of this image, with its center moved to the specified coordinates.
 WorldImage centerMoved(Posn xy)
          Produce a copy of this image, with its center moved to the specified coordinates.
protected  String cornerString()
          For debugging purposes; shows the coordinates of the bounding box of the image.
 WorldImage cropped(int left, int right, int top, int bottom)
          Get a new WorldImage by cropping this one to a rectangular window.
 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.
 Posn getCenter()
          Retrieve the coordinates of the center of the image.
 int getHeight()
          Retrieve the height of the image, in pixels.
 int getLeft()
          Getter for the left edge of the bounding box.
 Color getPixelColor(int x, int y)
          Get the color of a specified pixel of an image.
 int getTop()
          Getter for the top of the bounding box.
 int getWidth()
          Retrieve the width of the image, in pixels.
static void isApplet(boolean flag)
          Record whether or not we're in an applet.
static WorldImage makeCenteredCircle(Posn center, int radius)
          Produce an outlined black circle centered at a specified location.
static WorldImage makeCenteredCircle(Posn center, int radius, Color color)
          Produce an outlined circle centered at a specified location.
static WorldImage makeCenteredCircle(Posn center, int radius, Color color, Mode mode)
          Produce a circle centered at a specified location.
static WorldImage makeCenteredCircle(Posn center, int radius, IColor color)
          Produce an outlined circle centered at a specified location.
static WorldImage makeCenteredCircle(Posn center, int radius, IColor color, Mode mode)
          Produce a circle centered at a specified location.
static WorldImage makeCenteredCircle(Posn center, int radius, Mode mode)
          Produce a black circle centered at a specified location.
static WorldImage makeCircle(int radius)
          Produce an outlined black circle.
static WorldImage makeCircle(int radius, Color color)
          Produce an outlined circle.
static WorldImage makeCircle(int radius, Color color, Mode mode)
          Produce a circle.
static WorldImage makeCircle(int radius, IColor color)
          Produce an outlined circle.
static WorldImage makeCircle(int radius, IColor color, Mode mode)
          Produce a circle.
static WorldImage makeCircle(int radius, Mode mode)
          Produce a black circle.
static WorldImage makeEllipse(int width, int height)
          Produce an outlined black ellipse.
static WorldImage makeEllipse(int width, int height, Color color)
          Produce an outlined ellipse.
static WorldImage makeEllipse(int width, int height, Color color, Mode mode)
          Produce an ellipse.
static WorldImage makeEllipse(int width, int height, IColor color)
          Produce an outlined ellipse.
static WorldImage makeEllipse(int width, int height, IColor color, Mode mode)
          Produce an ellipse.
static WorldImage makeEllipse(int width, int height, Mode mode)
          Produce a black ellipse.
static WorldImage makeFromFile(String filename)
          Produce an image from a disk file (e.g. PNG, GIF, JPG, etc.)
static WorldImage makeFromURL(String urlString)
          Produce an image from a URL (e.g. "copy image location" in a Web browser)
 WorldImage makeImage()
          Produce a WorldImage representation of this object.
static WorldImage makeLine(Posn p1, Posn p2)
          Produce a black line segment with specified endpoints.
static WorldImage makeLine(Posn p1, Posn p2, Color color)
          Produce a line segment with specified endpoints.
static WorldImage makeLine(Posn p1, Posn p2, IColor color)
          Produce a line segment with specified endpoints.
static WorldImage makePolygon(Color color, Mode mode, Posn... points)
          Produce a polygon with specified vertices.
static WorldImage makePolygon(Color color, Posn... points)
          Produce an outlined polygon with specified vertices.
static WorldImage makePolygon(IColor color, Mode mode, Posn... points)
          Produce a polygon with specified vertices.
static WorldImage makePolygon(IColor color, Posn... points)
          Produce an outlined polygon with specified vertices.
static WorldImage makePolygon(Mode mode, Posn... points)
          Produce a black polygon with specified vertices.
static WorldImage makePolygon(Posn... points)
          Produce an outlined black polygon with specified vertices.
static WorldImage makeRectangle(int width, int height)
          Produce an outlined black rectangle.
static WorldImage makeRectangle(int width, int height, Color color)
          Produce an outlined rectangle.
static WorldImage makeRectangle(int width, int height, Color color, Mode mode)
          Produce a rectangle.
static WorldImage makeRectangle(int width, int height, IColor color)
          Produce an outlined rectangle.
static WorldImage makeRectangle(int width, int height, IColor color, Mode mode)
          Produce a rectangle.
static WorldImage makeRectangle(int width, int height, Mode mode)
          Produce a black rectangle.
static WorldImage makeText(String text)
          Produce an image of some text, defaulting to regular, 12-point, black.
static WorldImage makeText(String text, Color color)
          Produce an image of some text, defaulting to regular 12-point.
static WorldImage makeText(String text, float size)
          Produce an image of some text, defaulting to normal style and black.
static WorldImage makeText(String text, float size, Color color)
          Produce an image of some text, defaulting to normal style.
static WorldImage makeText(String text, float size, IColor color)
          Produce an image of some text, defaulting to normal style.
static WorldImage makeText(String text, float size, TextStyle style)
          Produce an image of some text, defaulting to black.
static WorldImage makeText(String text, float size, TextStyle style, Color color)
          Produce an image of some text.
static WorldImage makeText(String text, float size, TextStyle style, IColor color)
          Produce an image of some text.
static WorldImage makeText(String text, IColor color)
          Produce an image of some text, defaulting to regular 12-point.
static WorldImage makeText(String text, TextStyle style)
          Produce an image of some text, defaulting to 12-point black.
static WorldImage makeText(String text, TextStyle style, Color color)
          Produce an image of some text, defaulting to 12-point.
static WorldImage makeText(String text, TextStyle style, IColor color)
          Produce an image of some text, defgaulting to 12-point.
static WorldImage makeTriangle(double side)
          Produce an equilateral black outlined triangle with the specified side.
static WorldImage makeTriangle(double side, Color color)
          Produce an equilateral outlined triangle with the specified side and color.
static WorldImage makeTriangle(double side, Color color, Mode mode)
          Produce an equilateral triangle with the specified side, color, and mode.
static WorldImage makeTriangle(double side, IColor color)
          Produce an equilateral outlined triangle with the specified side and color.
static WorldImage makeTriangle(double side, IColor color, Mode mode)
          Produce an equilateral triangle with the specified side, color, and mode.
static WorldImage makeTriangle(double side, Mode mode)
          Produce an equilateral black triangle with the specified side and mode.
static WorldImage makeTriangle(Posn p1, Posn p2, Posn p3)
          Produce an outlined black triangle with specified vertices.
static WorldImage makeTriangle(Posn p1, Posn p2, Posn p3, Color color)
          Produce an outlined triangle with specified vertices.
static WorldImage makeTriangle(Posn p1, Posn p2, Posn p3, Color color, Mode mode)
          Produce a triangle with specified vertices.
static WorldImage makeTriangle(Posn p1, Posn p2, Posn p3, IColor color)
          Produce an outlined triangle with specified vertices.
static WorldImage makeTriangle(Posn p1, Posn p2, Posn p3, IColor color, Mode mode)
          Produce a triangle with specified vertices.
static WorldImage makeTriangle(Posn p1, Posn p2, Posn p3, Mode mode)
          Produce a black triangle with specified vertices.
 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 a translated copy of this image.
 WorldImage moved(Posn dxdy)
          Produce a translated copy of this image.
 WorldImage normalized()
          Produce a copy of this image translated to have its 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.
static WorldImage overlayImages(WorldImage... others)
          Produce an image by overlaying a bunch of existing images.
 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.
protected static int rotate(int x, int bits)
          A utility function for producing hash codes.
 WorldImage rotated(double degrees)
          Produce a copy of this image rotated by the specified number of degrees around the origin.
 WorldImage rotated(int degrees)
          Produce a copy of this image rotated by the specified number of degrees around the origin.
 WorldImage rotatedAround(double degrees, Posn anchor)
          Produce a copy of this image rotated by the specified number of degrees around the specified Posn.
 WorldImage rotatedAround(int degrees, Posn anchor)
          Produce a copy of this image rotated by the specified number of degrees around the specified Posn.
 WorldImage rotatedInPlace(double degrees)
          Produce a copy of this image rotated by the specified number of degrees around its center.
 WorldImage rotatedInPlace(int degrees)
          Produce a copy of this image rotated by the specified number of degrees around its center.
 boolean same(WorldImage other)
          Do two WorldImages appear the same? If they're equal as expression trees, they certainly appear the same.
 boolean sameClass(Object other)
          Is this the same class as some other object?
 boolean save(String filename)
          Save a WorldImage to a .png file.
 WorldImage scaled(double factor)
          Produce a copy of this image scaled by the specified factor.
 WorldImage scaled(double xFactor, double yFactor)
          Produce a copy of this image scaled differently in x and y dimensions.
 void show()
          Display the image in a new window by itself.
 String toString()
          Convert the image to String form, for debugging purposes.
 WorldImage xReflected()
          Produce a copy of this image reflected left to right, in place.
 WorldImage yReflected()
          get a vertically-reflected copy of the image.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javalib.worldimages.WorldImage
draw, getBottom, getRight, hashCode, toIndentedString
 

Constructor Detail

AImage

public AImage()
Method Detail

above

public WorldImage above(WorldImage... others)
Description copied from interface: WorldImage
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.

Specified by:
above in interface WorldImage
Parameters:
others - the images to concatenate below this, starting from the top
Returns:
a new WorldImage

aboveCentered

public WorldImage aboveCentered(WorldImage... others)
Description copied from interface: WorldImage
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.

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

beside

public WorldImage beside(WorldImage... others)
Description copied from interface: WorldImage
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.

Specified by:
beside in interface WorldImage
Parameters:
others - zero or more WorldImages
Returns:
a new WorldImage

besideCentered

public WorldImage besideCentered(WorldImage... others)
Description copied from interface: WorldImage
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.

Specified by:
besideCentered in interface WorldImage
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

build

public static WorldImage build(int width,
                               int height,
                               ImageBuilder builder)
Build a rectangular image pixel by pixel, with no "extra" information.

Parameters:
width - the width in pixels of the desired image
height - the height in pixels of the desired image
builder - an ImageBuilder specifying how to choose colors
Since:
Dec. 27, 2012

build

public static WorldImage build(int width,
                               int height,
                               ImageBuilder builder,
                               Object extra)
Build a rectangular image pixel by pixel.

Parameters:
width - the width in pixels of the desired image
height - the height in pixels of the desired image
builder - an ImageBuilder specifying how to choose colors
extra - an arbitrary Object to be passed to each call of the builder
Since:
Dec. 27, 2012

centerMoved

public WorldImage centerMoved(int x,
                              int y)
Produce a copy of this image, with its center moved to the specified coordinates.

Specified by:
centerMoved in interface WorldImage
Parameters:
x - where the center of the image should be after translation
y - where the center of the image should be after translation
Returns:
a new WorldImage, just like this one but translated.

centerMoved

public WorldImage centerMoved(Posn xy)
Produce a copy of this image, with its center moved to the specified coordinates.

Specified by:
centerMoved in interface WorldImage
Parameters:
xy - where the center of the image should be after translation
Returns:
a new WorldImage, just like this one but translated.

cornerString

protected String cornerString()
For debugging purposes; shows the coordinates of the bounding box of the image.


cropped

public WorldImage cropped(int left,
                          int right,
                          int top,
                          int bottom)
Description copied from interface: WorldImage
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.

Specified by:
cropped in interface WorldImage
Returns:
a new WorldImage which is a rectangular portion of this one

equals

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

Specified by:
equals in interface WorldImage
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

public RasterImage frozen()
Description copied from interface: WorldImage
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.

Specified by:
frozen in interface WorldImage
Returns:
a RasterImage that memoizes the rendering of this image

getCenter

public Posn getCenter()
Retrieve the coordinates of the center of the image.

Specified by:
getCenter in interface WorldImage
Returns:
a Posn indicating the center of the bounding box.

getHeight

public int getHeight()
Retrieve the height of the image, in pixels.

Specified by:
getHeight in interface WorldImage
Returns:
an int

getLeft

public int getLeft()
Getter for the left edge of the bounding box.

Specified by:
getLeft in interface WorldImage
Returns:
the minimum x coordinate of the image

getPixelColor

public Color getPixelColor(int x,
                           int y)
Description copied from interface: WorldImage
Get the color of a specified pixel of an image.

Specified by:
getPixelColor in interface WorldImage
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
the Color of the specified pixel.

getTop

public int getTop()
Getter for the top of the bounding box.

Specified by:
getTop in interface WorldImage
Returns:
the minimum y coordinate of the image

getWidth

public int getWidth()
Retrieve the width of the image, in pixels.

Specified by:
getWidth in interface WorldImage
Returns:
an int

isApplet

public static void isApplet(boolean flag)
Record whether or not we're in an applet.

Parameters:
flag -

makeCenteredCircle

public static WorldImage makeCenteredCircle(Posn center,
                                            int radius)
Produce an outlined black circle centered at a specified location.

Parameters:
center - the coordinates of the center
radius - the radius of the circle

makeCenteredCircle

public static WorldImage makeCenteredCircle(Posn center,
                                            int radius,
                                            Color color)
Produce an outlined circle centered at a specified location.

Parameters:
center - the coordinates of the center
radius - the radius of the circle
color - the color of the circle

makeCenteredCircle

public static WorldImage makeCenteredCircle(Posn center,
                                            int radius,
                                            Color color,
                                            Mode mode)
Produce a circle centered at a specified location.

Parameters:
center - the coordinates of the center
radius - the radius of the circle
color - the color of the circle
mode - either Mode.FILLED or Mode.OUTLINED

makeCenteredCircle

public static WorldImage makeCenteredCircle(Posn center,
                                            int radius,
                                            IColor color)
Produce an outlined circle centered at a specified location.

Parameters:
center - the coordinates of the center
radius - the radius of the circle
color - the color of the circle

makeCenteredCircle

public static WorldImage makeCenteredCircle(Posn center,
                                            int radius,
                                            IColor color,
                                            Mode mode)
Produce a circle centered at a specified location.

Parameters:
center - the coordinates of the center
radius - the radius of the circle
color - the color of the circle
mode - either Mode.FILLED or Mode.OUTLINED

makeCenteredCircle

public static WorldImage makeCenteredCircle(Posn center,
                                            int radius,
                                            Mode mode)
Produce a black circle centered at a specified location.

Parameters:
center - the coordinates of the center
radius - the radius of the circle
mode - either Mode.FILLED or Mode.OUTLINED

makeCircle

public static WorldImage makeCircle(int radius)
Produce an outlined black circle.

Parameters:
radius - the radius of the circle

makeCircle

public static WorldImage makeCircle(int radius,
                                    Color color)
Produce an outlined circle.

Parameters:
radius - the radius of the circle
color - the color of the circle

makeCircle

public static WorldImage makeCircle(int radius,
                                    Color color,
                                    Mode mode)
Produce a circle.

Parameters:
radius - the radius of the circle
color - the color of the circle
mode - either Mode.FILLED or Mode.OUTLINED

makeCircle

public static WorldImage makeCircle(int radius,
                                    IColor color)
Produce an outlined circle.

Parameters:
radius - the radius of the circle
color - the color of the circle

makeCircle

public static WorldImage makeCircle(int radius,
                                    IColor color,
                                    Mode mode)
Produce a circle.

Parameters:
radius - the radius of the circle
color - the color of the circle
mode - either Mode.FILLED or Mode.OUTLINED

makeCircle

public static WorldImage makeCircle(int radius,
                                    Mode mode)
Produce a black circle.

Parameters:
radius - the radius of the circle
mode - either Mode.FILLED or Mode.OUTLINED

makeEllipse

public static WorldImage makeEllipse(int width,
                                     int height)
Produce an outlined black ellipse.

Parameters:
width - the width in pixels
height - the height in pixels

makeEllipse

public static WorldImage makeEllipse(int width,
                                     int height,
                                     Color color)
Produce an outlined ellipse.

Parameters:
width - the width in pixels
height - the height in pixels
color - the color

makeEllipse

public static WorldImage makeEllipse(int width,
                                     int height,
                                     Color color,
                                     Mode mode)
Produce an ellipse.

Parameters:
width - the width in pixels
height - the height in pixels
color - the color
mode - either Mode.FILLED or Mode.OUTLINED

makeEllipse

public static WorldImage makeEllipse(int width,
                                     int height,
                                     IColor color)
Produce an outlined ellipse.

Parameters:
width - the width in pixels
height - the height in pixels
color - the color

makeEllipse

public static WorldImage makeEllipse(int width,
                                     int height,
                                     IColor color,
                                     Mode mode)
Produce an ellipse.

Parameters:
width - the width in pixels
height - the height in pixels
color - the color
mode - either Mode.FILLED or Mode.OUTLINED

makeEllipse

public static WorldImage makeEllipse(int width,
                                     int height,
                                     Mode mode)
Produce a black ellipse.

Parameters:
width - the width in pixels
height - the height in pixels
mode - either Mode.FILLED or Mode.OUTLINED

makeFromFile

public static WorldImage makeFromFile(String filename)
Produce an image from a disk file (e.g. PNG, GIF, JPG, etc.)

Parameters:
filename - the name of the disk file, interpreted relative to the project directory.

makeFromURL

public static WorldImage makeFromURL(String urlString)
Produce an image from a URL (e.g. "copy image location" in a Web browser)

Parameters:
urlString - the URL, written as a string

makeImage

public WorldImage makeImage()
Description copied from interface: Drawable
Produce a WorldImage representation of this object. You must provide a definition of this method in any class to be used as a model.

Specified by:
makeImage in interface Drawable
Returns:
a WorldImage

makeLine

public static WorldImage makeLine(Posn p1,
                                  Posn p2)
Produce a black line segment with specified endpoints.

Parameters:
p1 - the coordinates of one endpoint
p2 - the coordinates of the other endpoint

makeLine

public static WorldImage makeLine(Posn p1,
                                  Posn p2,
                                  Color color)
Produce a line segment with specified endpoints.

Parameters:
p1 - the coordinates of one endpoint
p2 - the coordinates of the other endpoint
color - the color of the line segment

makeLine

public static WorldImage makeLine(Posn p1,
                                  Posn p2,
                                  IColor color)
Produce a line segment with specified endpoints.

Parameters:
p1 - the coordinates of one endpoint
p2 - the coordinates of the other endpoint
color - the color of the line segment

makePolygon

public static WorldImage makePolygon(Color color,
                                     Mode mode,
                                     Posn... points)
Produce a polygon with specified vertices.

Parameters:
color - the color of the polygon
mode - either Mode.FILLED or Mode.OUTLINED
points - one or more Posns to indicate vertices

makePolygon

public static WorldImage makePolygon(Color color,
                                     Posn... points)
Produce an outlined polygon with specified vertices.

Parameters:
color - the color of the polygon
points - one or more Posns to indicate vertices

makePolygon

public static WorldImage makePolygon(IColor color,
                                     Mode mode,
                                     Posn... points)
Produce a polygon with specified vertices.

Parameters:
color - the color of the polygon
mode - either Mode.FILLED or Mode.OUTLINED
points - one or more Posns to indicate vertices

makePolygon

public static WorldImage makePolygon(IColor color,
                                     Posn... points)
Produce an outlined polygon with specified vertices.

Parameters:
color - the color of the polygon
points - one or more Posns to indicate vertices

makePolygon

public static WorldImage makePolygon(Mode mode,
                                     Posn... points)
Produce a black polygon with specified vertices.

Parameters:
mode - either Mode.FILLED or Mode.OUTLINED
points - one or more Posns to indicate vertices

makePolygon

public static WorldImage makePolygon(Posn... points)
Produce an outlined black polygon with specified vertices.

Parameters:
points - one or more Posns to indicate vertices

makeRectangle

public static WorldImage makeRectangle(int width,
                                       int height)
Produce an outlined black rectangle.

Parameters:
width - the width in pixels
height - the height in pixels

makeRectangle

public static WorldImage makeRectangle(int width,
                                       int height,
                                       Color color)
Produce an outlined rectangle.

Parameters:
width - the width in pixels
height - the height in pixels
color - the color

makeRectangle

public static WorldImage makeRectangle(int width,
                                       int height,
                                       Color color,
                                       Mode mode)
Produce a rectangle.

Parameters:
width - the width in pixels
height - the height in pixels
color - the color
mode - either Mode.FILLED or Mode.OUTLINED

makeRectangle

public static WorldImage makeRectangle(int width,
                                       int height,
                                       IColor color)
Produce an outlined rectangle.

Parameters:
width - the width in pixels
height - the height in pixels
color - the color

makeRectangle

public static WorldImage makeRectangle(int width,
                                       int height,
                                       IColor color,
                                       Mode mode)
Produce a rectangle.

Parameters:
width - the width in pixels
height - the height in pixels
color - the color
mode - either Mode.FILLED or Mode.OUTLINED

makeRectangle

public static WorldImage makeRectangle(int width,
                                       int height,
                                       Mode mode)
Produce a black rectangle.

Parameters:
width - the width in pixels
height - the height in pixels
mode - either Mode.FILLED or Mode.OUTLINED

makeText

public static WorldImage makeText(String text)
Produce an image of some text, defaulting to regular, 12-point, black.

Parameters:
text - the String to convert into an image

makeText

public static WorldImage makeText(String text,
                                  Color color)
Produce an image of some text, defaulting to regular 12-point.

Parameters:
text - the String to convert into an image
color - the color of the text (default black)

makeText

public static WorldImage makeText(String text,
                                  float size)
Produce an image of some text, defaulting to normal style and black.

Parameters:
text - the String to convert into an image
size - the size in points (e.g. 12.0 is 12-point font)
color - the color of the text (default black)

makeText

public static WorldImage makeText(String text,
                                  float size,
                                  Color color)
Produce an image of some text, defaulting to normal style.

Parameters:
text - the String to convert into an image
size - the size in points (e.g. 12.0 is 12-point font)
color - the color of the text (default black)

makeText

public static WorldImage makeText(String text,
                                  float size,
                                  IColor color)
Produce an image of some text, defaulting to normal style.

Parameters:
text - the String to convert into an image
size - the size in points (e.g. 12.0 is 12-point font)
color - the color of the text (default black)

makeText

public static WorldImage makeText(String text,
                                  float size,
                                  TextStyle style)
Produce an image of some text, defaulting to black.

Parameters:
text - the String to convert into an image
size - the size in points (e.g. 12.0 is 12-point font)
style - either TextStyle.NORMAL (the default, also known as TextStyle.REGULAR), TextStyle.BOLD, TextStyle,ITALIC, or TextStyle.BOLD_ITALIC (also known as TextStyle.ITALIC_BOLD)

makeText

public static WorldImage makeText(String text,
                                  float size,
                                  TextStyle style,
                                  Color color)
Produce an image of some text.

Parameters:
text - the String to convert into an image
size - the size in points (e.g. 12.0 is 12-point font)
style - either TextStyle.NORMAL (the default, also known as TextStyle.REGULAR), TextStyle.BOLD, TextStyle,ITALIC, or TextStyle.BOLD_ITALIC (also known as TextStyle.ITALIC_BOLD)
color - the color of the text (default black)

makeText

public static WorldImage makeText(String text,
                                  float size,
                                  TextStyle style,
                                  IColor color)
Produce an image of some text.

Parameters:
text - the String to convert into an image
size - the size in points (e.g. 12.0 is 12-point font)
style - either TextStyle.NORMAL (the default, also known as TextStyle.REGULAR), TextStyle.BOLD, TextStyle,ITALIC, or TextStyle.BOLD_ITALIC (also known as TextStyle.ITALIC_BOLD)
color - the color of the text (default black)

makeText

public static WorldImage makeText(String text,
                                  IColor color)
Produce an image of some text, defaulting to regular 12-point.

Parameters:
text - the String to convert into an image
color - the color of the text (default black)

makeText

public static WorldImage makeText(String text,
                                  TextStyle style)
Produce an image of some text, defaulting to 12-point black.

Parameters:
text - the String to convert into an image
style - either TextStyle.NORMAL (the default, also known as TextStyle.REGULAR), TextStyle.BOLD, TextStyle,ITALIC, or TextStyle.BOLD_ITALIC (also known as TextStyle.ITALIC_BOLD)

makeText

public static WorldImage makeText(String text,
                                  TextStyle style,
                                  Color color)
Produce an image of some text, defaulting to 12-point.

Parameters:
text - the String to convert into an image
style - either TextStyle.NORMAL (the default, also known as TextStyle.REGULAR), TextStyle.BOLD, TextStyle,ITALIC, or TextStyle.BOLD_ITALIC (also known as TextStyle.ITALIC_BOLD)
color - the color of the text (default black)

makeText

public static WorldImage makeText(String text,
                                  TextStyle style,
                                  IColor color)
Produce an image of some text, defgaulting to 12-point.

Parameters:
text - the String to convert into an image
style - either TextStyle.NORMAL (the default, also known as TextStyle.REGULAR), TextStyle.BOLD, TextStyle,ITALIC, or TextStyle.BOLD_ITALIC (also known as TextStyle.ITALIC_BOLD)
color - the color of the text (default black)

makeTriangle

public static WorldImage makeTriangle(double side)
Produce an equilateral black outlined triangle with the specified side.

Parameters:
side - the length of each side of the triangle
Since:
Feb. 7, 2013

makeTriangle

public static WorldImage makeTriangle(double side,
                                      Color color)
Produce an equilateral outlined triangle with the specified side and color.

Parameters:
side - the length of each side of the triangle
color - the color of the triangle
Since:
Feb. 7, 2013

makeTriangle

public static WorldImage makeTriangle(double side,
                                      Color color,
                                      Mode mode)
Produce an equilateral triangle with the specified side, color, and mode.

Parameters:
side - the length of each side of the triangle
color - the color of the triangle
mode - either Mode.FILLED or Mode.OUTLINED
Since:
Feb. 7, 2013

makeTriangle

public static WorldImage makeTriangle(double side,
                                      IColor color)
Produce an equilateral outlined triangle with the specified side and color.

Parameters:
side - the length of each side of the triangle
color - the color of the triangle
Since:
Feb. 7, 2013

makeTriangle

public static WorldImage makeTriangle(double side,
                                      IColor color,
                                      Mode mode)
Produce an equilateral triangle with the specified side, color, and mode.

Parameters:
side - the length of each side of the triangle
color - the color of the triangle
mode - either Mode.FILLED or Mode.OUTLINED
Since:
Feb. 7, 2013

makeTriangle

public static WorldImage makeTriangle(double side,
                                      Mode mode)
Produce an equilateral black triangle with the specified side and mode.

Parameters:
side - the length of each side of the triangle
mode - either Mode.FILLED or Mode.OUTLINED
Since:
Feb. 7, 2013

makeTriangle

public static WorldImage makeTriangle(Posn p1,
                                      Posn p2,
                                      Posn p3)
Produce an outlined black triangle with specified vertices.

Parameters:
p1 - the coordinates of one vertex
p2 - the coordinates of another vertex
p3 - the coordinates of the third vertex

makeTriangle

public static WorldImage makeTriangle(Posn p1,
                                      Posn p2,
                                      Posn p3,
                                      Color color)
Produce an outlined triangle with specified vertices.

Parameters:
p1 - the coordinates of one vertex
p2 - the coordinates of another vertex
p3 - the coordinates of the third vertex
color - the color of the triangle

makeTriangle

public static WorldImage makeTriangle(Posn p1,
                                      Posn p2,
                                      Posn p3,
                                      Color color,
                                      Mode mode)
Produce a triangle with specified vertices.

Parameters:
p1 - the coordinates of one vertex
p2 - the coordinates of another vertex
p3 - the coordinates of the third vertex
color - the color of the triangle
mode - either Mode.FILLED or Mode.OUTLINED

makeTriangle

public static WorldImage makeTriangle(Posn p1,
                                      Posn p2,
                                      Posn p3,
                                      IColor color)
Produce an outlined triangle with specified vertices.

Parameters:
p1 - the coordinates of one vertex
p2 - the coordinates of another vertex
p3 - the coordinates of the third vertex
color - the color of the triangle

makeTriangle

public static WorldImage makeTriangle(Posn p1,
                                      Posn p2,
                                      Posn p3,
                                      IColor color,
                                      Mode mode)
Produce a triangle with specified vertices.

Parameters:
p1 - the coordinates of one vertex
p2 - the coordinates of another vertex
p3 - the coordinates of the third vertex
color - the color of the triangle
mode - either Mode.FILLED or Mode.OUTLINED

makeTriangle

public static WorldImage makeTriangle(Posn p1,
                                      Posn p2,
                                      Posn p3,
                                      Mode mode)
Produce a black triangle with specified vertices.

Parameters:
p1 - the coordinates of one vertex
p2 - the coordinates of another vertex
p3 - the coordinates of the third vertex
mode - either Mode.FILLED or Mode.OUTLINED

map

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

Specified by:
map in interface WorldImage
Parameters:
map - an ImageMap encapsulating a function from Color to Color
Returns:
a new image the same size and shape as this

map

public WorldImage map(ImageMap map,
                      Object extra)
Description copied from interface: WorldImage
Create a rectangular image pixel by pixel from an existing image.

Specified by:
map in interface WorldImage
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

moved

public WorldImage moved(int dx,
                        int dy)
Produce a translated copy of this image.

Specified by:
moved in interface WorldImage
Parameters:
dx - how far to move to the right (or left, if dx is negative)
dy - how far to move down (or up, if dy is negative)
Returns:
a new WorldImage, just like this one but translated.

moved

public WorldImage moved(Posn dxdy)
Produce a translated copy of this image.

Specified by:
moved in interface WorldImage
Parameters:
dxdy - a Posn indicating how far to move
Returns:
a new WorldImage, just like this one but translated.

normalized

public WorldImage normalized()
Produce a copy of this image translated to have its top-left corner at (0,0).

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

overlay

public WorldImage overlay(WorldImage... others)
Description copied from interface: WorldImage
Overlay other images on this one, retaining their locations.

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

overlayCentered

public WorldImage overlayCentered(WorldImage... others)
Description copied from interface: WorldImage
Overlay other images on this one, ignoring location of all but centering them.

Specified by:
overlayCentered in interface WorldImage
Parameters:
others - one or more images to overlay on this one.
Returns:
a new WorldImage

overlayImages

public static WorldImage overlayImages(WorldImage... others)
Produce an image by overlaying a bunch of existing images.

Parameters:
others - two or more images to be overlaid
Returns:
a new image, or null if there were none

overlayXY

public WorldImage overlayXY(WorldImage front,
                            int dx,
                            int dy)
Description copied from interface: WorldImage
Overlay another image on this one, retaining locations and translating the other image.

Specified by:
overlayXY in interface WorldImage
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

public WorldImage place(WorldImage front,
                        int x,
                        int y)
Description copied from interface: WorldImage
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.

Specified by:
place in interface WorldImage
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

rotate

protected static int rotate(int x,
                            int bits)
A utility function for producing hash codes.

Parameters:
x - a hashCode for some field
bits - how many bits to rotate it within a 32-bit int
Returns:
x rotated left by the specified number of bits (wrapping around to the low bits)

rotated

public WorldImage rotated(double degrees)
Produce a copy of this image rotated by the specified number of degrees around the origin.

Specified by:
rotated in interface WorldImage
Parameters:
degrees - how many degrees to rotate, counter-clockwise (I think!)
Returns:
a new WorldImage, just like this one but rotated.

rotated

public WorldImage rotated(int degrees)
Produce a copy of this image rotated by the specified number of degrees around the origin.

Specified by:
rotated in interface WorldImage
Parameters:
degrees - how many degrees to rotate, counter-clockwise (I think!)
Returns:
a new WorldImage, just like this one but rotated.

rotatedAround

public WorldImage rotatedAround(double degrees,
                                Posn anchor)
Produce a copy of this image rotated by the specified number of degrees around the specified Posn.

Specified by:
rotatedAround in interface WorldImage
Parameters:
degrees - how many degrees to rotate, counter-clockwise (I think!)
anchor - the Posn to rotate around
Returns:
a new WorldImage, just like this one but rotated.

rotatedAround

public WorldImage rotatedAround(int degrees,
                                Posn anchor)
Produce a copy of this image rotated by the specified number of degrees around the specified Posn.

Specified by:
rotatedAround in interface WorldImage
Parameters:
degrees - how many degrees to rotate, counter-clockwise (I think!)
anchor - the Posn to rotate around
Returns:
a new WorldImage, just like this one but rotated.

rotatedInPlace

public WorldImage rotatedInPlace(double degrees)
Produce a copy of this image rotated by the specified number of degrees around its center.

Specified by:
rotatedInPlace in interface WorldImage
Parameters:
degrees - how many degrees to rotate, counter-clockwise (I think!)
Returns:
a new WorldImage, just like this one but rotated.

rotatedInPlace

public WorldImage rotatedInPlace(int degrees)
Produce a copy of this image rotated by the specified number of degrees around its center.

Specified by:
rotatedInPlace in interface WorldImage
Parameters:
degrees - how many degrees to rotate, counter-clockwise (I think!)
Returns:
a new WorldImage, just like this one but rotated.

same

public boolean same(WorldImage other)
Do two WorldImages appear the same? If they're equal as expression trees, they certainly appear the same. Failing that, render them both and compare the pixel maps.

Specified by:
same in interface WorldImage
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

sameClass

public boolean sameClass(Object other)
Is this the same class as some other object?

Parameters:
other -
Returns:
true iff they're exactly the same class

save

public boolean save(String filename)
Description copied from interface: WorldImage
Save a WorldImage to a .png file.

Specified by:
save in interface WorldImage
Returns:
true if the file was saved successfully.

scaled

public WorldImage scaled(double factor)
Produce a copy of this image scaled by the specified factor.

Specified by:
scaled in interface WorldImage
Parameters:
factor - the scaling factor (e.g. 2.0 means it doubles in size)
Returns:
a new WorldImage which is factor times as large as this one.

scaled

public WorldImage scaled(double xFactor,
                         double yFactor)
Produce a copy of this image scaled differently in x and y dimensions.

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

show

public void show()
Display the image in a new window by itself. Primarily for debugging purposes.

Specified by:
show in interface WorldImage

toString

public String toString()
Convert the image to String form, for debugging purposes.

Specified by:
toString in interface WorldImage
Overrides:
toString in class Object
Returns:
the String representation of this image

xReflected

public WorldImage xReflected()
Produce a copy of this image reflected left to right, in place.

Specified by:
xReflected in interface WorldImage
Returns:
a new WorldImage just like this one but reflected.

yReflected

public WorldImage yReflected()
Description copied from interface: WorldImage
get a vertically-reflected copy of the image.

Specified by:
yReflected in interface WorldImage
Returns:
a new WorldImage just like this one but reflected.