edu.neu.ccs.gui
Class PaintTools

java.lang.Object
  extended byedu.neu.ccs.gui.PaintTools

public class PaintTools
extends Object

The class PaintTools contains static methods that use PaintAlgorithm objects to make other useful objects such as TexturePaint objects and BufferedImage objects; the class also contains static methods that manipulate PaintAlgorithm objects to create new objects that may be used to define hatch patterns.

Since:
2.3.2
Version:
2.3.2

Constructor Summary
private PaintTools()
          This class cannot be instantiated.
 
Method Summary
static PaintAlgorithm brickEtoW(Color cellColor, Color edgeColor, int size)
          Returns a brick pattern oriented horizontally (EW) such that the brick cell has dimensions width = 2 * size, height = size and uses the given cell color and edge color.
static PaintAlgorithm brickNEtoSW(Color cellColor, Color edgeColor, int size)
          Equivalent to turn45(brickEtoW(args)).
static PaintAlgorithm brickNtoS(Color cellColor, Color edgeColor, int size)
          Equivalent to turn90(brickEtoW(args)).
static PaintAlgorithm brickNWtoSE(Color cellColor, Color edgeColor, int size)
          Equivalent to turn135(brickEtoW(args)).
static PaintAlgorithm checkHatch(Color color1, Color color2, int width1, int width2, int height1, int height2)
          Returns a checker board hatch pattern.
static PaintAlgorithm checkHatch(PaintAlgorithm algorithm1, PaintAlgorithm algorithm2, int width1, int width2, int height1, int height2)
          Returns a check board hatch pattern.
static PaintAlgorithm checkHatchDiagonal(Color color1, Color color2, int width1, int width2, int height1, int height2)
          Equivalent to turn45(checkHatch(args)).
static PaintAlgorithm checkHatchDiagonal(PaintAlgorithm algorithm1, PaintAlgorithm algorithm2, int width1, int width2, int height1, int height2)
          Equivalent to turn45(checkHatch(args)).
static PaintAlgorithm crossHatch(Color color1, Color color2, int width1, int width2, int height1, int height2)
          Returns a cross hatch pattern.
static PaintAlgorithm crossHatch(PaintAlgorithm algorithm1, PaintAlgorithm algorithm2, int width1, int width2, int height1, int height2)
          Returns a cross hatch pattern.
static PaintAlgorithm crossHatchDiagonal(Color color1, Color color2, int width1, int width2, int height1, int height2)
          Equivalent to turn45(crossHatch(args)).
static PaintAlgorithm crossHatchDiagonal(PaintAlgorithm algorithm1, PaintAlgorithm algorithm2, int width1, int width2, int height1, int height2)
          Equivalent to turn45(crossHatch(args)).
static PaintAlgorithm dottedGrid(Color dotColor, Color backColor, int dotSize, int gridSize)
          Returns a dotted grid pattern with the given dot color and background color.
static PaintAlgorithm dottedGridDiagonal(Color dotColor, Color backColor, int dotSize, int gridSize)
          Equivalent to turn45(dottedGrid(args)).
static BufferedImage makeBufferedImage(PaintAlgorithm algorithm)
          Returns a BufferedImage object whose pixel colors are defined by the given algorithm and whose size is determined by the periods in the given algorithm.
static BufferedImage makeBufferedImage(PaintAlgorithm algorithm, int width, int height)
          Returns a BufferedImage object whose pixel colors are defined by the given algorithm and whose size is determined by the given width and height.
static TexturePaint makePaint(PaintAlgorithm algorithm)
          Returns a TexturePaint object whose pixel colors are defined by the given algorithm and whose size is determined by the periods in the given algorithm.
static TexturePaint makePaint(PaintAlgorithm algorithm, int width, int height)
          Returns a TexturePaint object whose pixel colors are defined by the given algorithm and whose size is determined by the given width and height.
static PaintAlgorithm makePaintAlgorithm(BufferedImage image)
          Returns a PaintAlgorithm whose color mapping is determined by the color data in the given buffered image.
static PaintAlgorithm reflect(PaintAlgorithm algorithm)
          Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that reflects through the x-axis.
static PaintAlgorithm solid(Color c)
          Returns the PaintAlgorithm that returns the given solid color for any x and y input.
static PaintAlgorithm stripeEtoW(Color color1, Color color2, int thick1, int thick2)
          Returns the PaintAlgorithm that draws a pair of stripes from east to west with stripe 1 using color color1 with thickness thick1 and with stripe 2 using color color2 with thickness thick2.
static PaintAlgorithm stripeEtoW(PaintAlgorithm algorithm1, PaintAlgorithm algorithm2, int thick1, int thick2)
          Returns the PaintAlgorithm that draws a pair of stripes from east to west with stripe 1 using algorithm1 with thickness thick1 and with stripe 2 using algorithm2 with thickness thick2.
static PaintAlgorithm stripeNEtoSW(Color color1, Color color2, int thick1, int thick2)
          Equivalent to turn45(stripeEtoW(args)).
static PaintAlgorithm stripeNEtoSW(PaintAlgorithm algorithm1, PaintAlgorithm algorithm2, int thick1, int thick2)
          Equivalent to turn45(stripeEtoW(args)).
static PaintAlgorithm stripeNtoS(Color color1, Color color2, int thick1, int thick2)
          Equivalent to turn90(stripeEtoW(args)).
static PaintAlgorithm stripeNtoS(PaintAlgorithm algorithm1, PaintAlgorithm algorithm2, int thick1, int thick2)
          Equivalent to turn90(stripeEtoW(args)).
static PaintAlgorithm stripeNWtoSE(Color color1, Color color2, int thick1, int thick2)
          Equivalent to turn135(stripeEtoW(args)).
static PaintAlgorithm stripeNWtoSE(PaintAlgorithm algorithm1, PaintAlgorithm algorithm2, int thick1, int thick2)
          Equivalent to turn135(stripeEtoW(args)).
static PaintAlgorithm translate(PaintAlgorithm algorithm, int x0, int y0)
          Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that translates by the given x0, y0.
static PaintAlgorithm turn135(PaintAlgorithm algorithm)
          Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 135 degrees.
static PaintAlgorithm turn180(PaintAlgorithm algorithm)
          Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 180 degrees.
static PaintAlgorithm turn225(PaintAlgorithm algorithm)
          Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 225 degrees.
static PaintAlgorithm turn270(PaintAlgorithm algorithm)
          Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 270 degrees.
static PaintAlgorithm turn315(PaintAlgorithm algorithm)
          Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 45 degrees.
static PaintAlgorithm turn45(PaintAlgorithm algorithm)
          Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 45 degrees.
static PaintAlgorithm turn90(PaintAlgorithm algorithm)
          Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 90 degrees.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PaintTools

private PaintTools()
This class cannot be instantiated.

Method Detail

makePaint

public static TexturePaint makePaint(PaintAlgorithm algorithm)

Returns a TexturePaint object whose pixel colors are defined by the given algorithm and whose size is determined by the periods in the given algorithm.

Returns null if the given algorithm is null.

Parameters:
algorithm - the algorithm to construct the texture paint
Returns:
the constructed texture paint

makePaint

public static TexturePaint makePaint(PaintAlgorithm algorithm,
                                     int width,
                                     int height)

Returns a TexturePaint object whose pixel colors are defined by the given algorithm and whose size is determined by the given width and height.

Returns null if the given algorithm is null or if either the given width or height is less than or equal to zero.

Parameters:
algorithm - the algorithm to construct the paint
width - the width of the texture paint swatch
height - the height of the texture paint swatch
Returns:
the constructed texture paint

makeBufferedImage

public static BufferedImage makeBufferedImage(PaintAlgorithm algorithm)

Returns a BufferedImage object whose pixel colors are defined by the given algorithm and whose size is determined by the periods in the given algorithm.

Returns null if the given algorithm is null.

Parameters:
algorithm - the algorithm to construct the buffered image
Returns:
the constructed buffered image

makeBufferedImage

public static BufferedImage makeBufferedImage(PaintAlgorithm algorithm,
                                              int width,
                                              int height)

Returns a BufferedImage object whose pixel colors are defined by the given algorithm and whose size is determined by the given width and height.

Returns null if the given algorithm is null or if either the given width or height is less than or equal to zero.

Parameters:
algorithm - the algorithm to construct the buffered image
width - the width of the texture paint swatch
height - the height of the texture paint swatch
Returns:
the constructed buffered image

makePaintAlgorithm

public static PaintAlgorithm makePaintAlgorithm(BufferedImage image)

Returns a PaintAlgorithm whose color mapping is determined by the color data in the given buffered image.

Returns null if the given buffered image is null or empty.

Copies the given buffered image information to provide permanent data for the algorithm.

Parameters:
image - the buffered image to convert to an algorithm
Returns:
a paint algorithm based on the buffered image

solid

public static PaintAlgorithm solid(Color c)

Returns the PaintAlgorithm that returns the given solid color for any x and y input.

The x and y periods of the algorithm are both 1.

If the given color is null, this method uses as its default Color.black.

Parameters:
c - the solid color for the algorithm
Returns:
the algorithm encapsulating the solid color

turn45

public static PaintAlgorithm turn45(PaintAlgorithm algorithm)

Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 45 degrees.

More precisely, for any (x, y), the new algorithm at (x, y) will be computed as:

algorithm.color(x - y, x + y)

If this algorithm is used to construct a texture paint, it will appear that the new paint is geometrically contracted by sqrt(2) relative to the size of the old paint (as well as rotated).

The x and y periods of the resulting algorithm are both equal to the least common multiple of the x and y periods of the given algorithm.

If the given algorithm is null, returns null.

Parameters:
algorithm - the paint algorithm to rotate
Returns:
the rotated paint algorithm

turn90

public static PaintAlgorithm turn90(PaintAlgorithm algorithm)

Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 90 degrees.

More precisely, for any (x, y), the new algorithm at (x, y) will be computed as:

algorithm.color(- y, x)

If this algorithm is used to construct a texture paint, the new paint is geometrically the same size as the old paint (but rotated).

The x and y periods of the resulting algorithm are interchanged with the x and y periods of the given algorithm.

If the given algorithm is null, returns null.

Parameters:
algorithm - the paint algorithm to rotate
Returns:
the rotated paint algorithm

turn135

public static PaintAlgorithm turn135(PaintAlgorithm algorithm)

Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 135 degrees.

More precisely, for any (x, y), the new algorithm at (x, y) will be computed as:

algorithm.color(- x - y, x - y)

If this algorithm is used to construct a texture paint, it will appear that the new paint is geometrically contracted by sqrt(2) relative to the size of the old paint (as well as rotated).

The x and y periods of the resulting algorithm are both equal to the least common multiple of the x and y periods of the given algorithm.

If the given algorithm is null, returns null.

Parameters:
algorithm - the paint algorithm to rotate
Returns:
the rotated paint algorithm

turn180

public static PaintAlgorithm turn180(PaintAlgorithm algorithm)

Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 180 degrees.

More precisely, for any (x, y), the new algorithm at (x, y) will be computed as:

algorithm.color(- x, - y)

If this algorithm is used to construct a texture paint, the new paint is geometrically the same size as the old paint (but rotated).

The x and y periods of the resulting algorithm are the same as the x and y periods of the given algorithm.

If the given algorithm is null, returns null.

Parameters:
algorithm - the paint algorithm to rotate
Returns:
the rotated paint algorithm

turn225

public static PaintAlgorithm turn225(PaintAlgorithm algorithm)

Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 225 degrees.

More precisely, for any (x, y), the new algorithm at (x, y) will be computed as:

algorithm.color(- x + y, - x - y)

If this algorithm is used to construct a texture paint, it will appear that the new paint is geometrically contracted by sqrt(2) relative to the size of the old paint (as well as rotated).

The x and y periods of the resulting algorithm are both equal to the least common multiple of the x and y periods of the given algorithm.

If the given algorithm is null, returns null.

Parameters:
algorithm - the paint algorithm to rotate
Returns:
the rotated paint algorithm

turn270

public static PaintAlgorithm turn270(PaintAlgorithm algorithm)

Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 270 degrees.

More precisely, for any (x, y), the new algorithm at (x, y) will be computed as:

algorithm.color(y, - x)

If this algorithm is used to construct a texture paint, the new paint is geometrically the same size as the old paint (but rotated).

The x and y periods of the resulting algorithm are interchanged with the x and y periods of the given algorithm.

If the given algorithm is null, returns null.

Parameters:
algorithm - the paint algorithm to rotate
Returns:
the rotated paint algorithm

turn315

public static PaintAlgorithm turn315(PaintAlgorithm algorithm)

Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that rotates by 45 degrees.

More precisely, for any (x, y), the new algorithm at (x, y) will be computed as:

algorithm.color(x + y, - x + y)

If this algorithm is used to construct a texture paint, it will appear that the new paint is geometrically contracted by sqrt(2) relative to the size of the old paint (as well as rotated).

The x and y periods of the resulting algorithm are both equal to the least common multiple of the x and y periods of the given algorithm.

If the given algorithm is null, returns null.

Parameters:
algorithm - the paint algorithm to rotate
Returns:
the rotated paint algorithm

reflect

public static PaintAlgorithm reflect(PaintAlgorithm algorithm)

Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that reflects through the x-axis.

More precisely, for any (x, y), the new algorithm at (x, y) will be computed as:

algorithm.color(x, - y)

If this algorithm is used to construct a texture paint, the new paint is geometrically the same size as the old paint (but reflected).

The x and y periods of the resulting algorithm are the same as the x and y periods of the given algorithm.

Other useful reflections may be obtained by compositions of the form turnN(reflect(algorithm)) for N = 45, 90, 135, 180, 215, 270, 315. For this reason, such reflections are not given as separate methods.

If the given algorithm is null, returns null.

Parameters:
algorithm - the paint algorithm to reflect
Returns:
the reflected paint algorithm

translate

public static PaintAlgorithm translate(PaintAlgorithm algorithm,
                                       int x0,
                                       int y0)

Returns a PaintAlgorithm constructed from the given PaintAlgorithm by composition with a transform that translates by the given x0, y0.

More precisely, for any (x, y), the new algorithm at (x, y) will be computed as:

algorithm.color(x - x0, y - y0)

The x and y periods of the resulting algorithm are the same as the x and y periods of the given algorithm.

If the given algorithm is null, returns null.

Parameters:
algorithm - the paint algorithm to reflect
x0 - the x translation
y0 - the y translation
Returns:
the reflected paint algorithm

stripeEtoW

public static PaintAlgorithm stripeEtoW(Color color1,
                                        Color color2,
                                        int thick1,
                                        int thick2)

Returns the PaintAlgorithm that draws a pair of stripes from east to west with stripe 1 using color color1 with thickness thick1 and with stripe 2 using color color2 with thickness thick2.

The x period is 1.

The y period is thick1 + thick2.

Parameters:
color1 - the color for stripe 1
color2 - the color for stripe 2
thick1 - the thickness of stripe 1
thick2 - the thickness of stripe 2
Returns:
a paint algorithm for the stripe

stripeEtoW

public static PaintAlgorithm stripeEtoW(PaintAlgorithm algorithm1,
                                        PaintAlgorithm algorithm2,
                                        int thick1,
                                        int thick2)

Returns the PaintAlgorithm that draws a pair of stripes from east to west with stripe 1 using algorithm1 with thickness thick1 and with stripe 2 using algorithm2 with thickness thick2.

The x period is the least common multiple of the x periods of the given algorithms.

The y period is thick1 + thick2.

If either algorithm is null, returns null.

Parameters:
algorithm1 - the paint algorithm for stripe 1
algorithm2 - the paint algorithm for stripe 2
thick1 - the thickness of stripe 1
thick2 - the thickness of stripe 2
Returns:
a paint algorithm for the stripe

stripeNEtoSW

public static PaintAlgorithm stripeNEtoSW(Color color1,
                                          Color color2,
                                          int thick1,
                                          int thick2)

Equivalent to turn45(stripeEtoW(args)).


stripeNEtoSW

public static PaintAlgorithm stripeNEtoSW(PaintAlgorithm algorithm1,
                                          PaintAlgorithm algorithm2,
                                          int thick1,
                                          int thick2)

Equivalent to turn45(stripeEtoW(args)).


stripeNtoS

public static PaintAlgorithm stripeNtoS(Color color1,
                                        Color color2,
                                        int thick1,
                                        int thick2)

Equivalent to turn90(stripeEtoW(args)).


stripeNtoS

public static PaintAlgorithm stripeNtoS(PaintAlgorithm algorithm1,
                                        PaintAlgorithm algorithm2,
                                        int thick1,
                                        int thick2)

Equivalent to turn90(stripeEtoW(args)).


stripeNWtoSE

public static PaintAlgorithm stripeNWtoSE(Color color1,
                                          Color color2,
                                          int thick1,
                                          int thick2)

Equivalent to turn135(stripeEtoW(args)).


stripeNWtoSE

public static PaintAlgorithm stripeNWtoSE(PaintAlgorithm algorithm1,
                                          PaintAlgorithm algorithm2,
                                          int thick1,
                                          int thick2)

Equivalent to turn135(stripeEtoW(args)).


checkHatch

public static PaintAlgorithm checkHatch(Color color1,
                                        Color color2,
                                        int width1,
                                        int width2,
                                        int height1,
                                        int height2)

Returns a checker board hatch pattern.

The colors are arranged in the cells as follows:

    color1    color2
    color2    color1
 

The cell widths and heights use the given values.

The x period is width1 + width2.

The y period is height1 + height2.

Parameters:
color1 - the color for 2 of 4 cells
color2 - the color for 2 of 4 cells
width1 - the width of column 1
width2 - the width of column 2
height1 - the height of row 1
height2 - the height of row 2
Returns:
a paint algorithm for the checker board

checkHatch

public static PaintAlgorithm checkHatch(PaintAlgorithm algorithm1,
                                        PaintAlgorithm algorithm2,
                                        int width1,
                                        int width2,
                                        int height1,
                                        int height2)

Returns a check board hatch pattern.

The algorithms are applied to the cells as follows:

    algorithm1    algorithm2
    algorithm2    algorithm1
 

The cell widths and heights use the given values.

The x period is width1 + width2.

The y period is height1 + height2.

If either algorithm is null, returns null.

Parameters:
algorithm1 - the algorithm for 2 of 4 cells
algorithm2 - the algorithm for 2 of 4 cells
width1 - the width of column 1
width2 - the width of column 2
height1 - the height of row 1
height2 - the height of row 2
Returns:
a paint algorithm for the checker board

checkHatchDiagonal

public static PaintAlgorithm checkHatchDiagonal(Color color1,
                                                Color color2,
                                                int width1,
                                                int width2,
                                                int height1,
                                                int height2)

Equivalent to turn45(checkHatch(args)).


checkHatchDiagonal

public static PaintAlgorithm checkHatchDiagonal(PaintAlgorithm algorithm1,
                                                PaintAlgorithm algorithm2,
                                                int width1,
                                                int width2,
                                                int height1,
                                                int height2)

Equivalent to turn45(checkHatch(args)).


crossHatch

public static PaintAlgorithm crossHatch(Color color1,
                                        Color color2,
                                        int width1,
                                        int width2,
                                        int height1,
                                        int height2)

Returns a cross hatch pattern.

The colors are arranged in the cells as follows:

    color1    color1
    color1    color2
 

The cell widths and heights use the given values.

The x period is width1 + width2.

The y period is height1 + height2.

Parameters:
color1 - the color for 3 of 4 cells
color2 - the color for 1 of 4 cells
width1 - the width of column 1
width2 - the width of column 2
height1 - the height of row 1
height2 - the height of row 2
Returns:
a paint algorithm for the cross hatch

crossHatch

public static PaintAlgorithm crossHatch(PaintAlgorithm algorithm1,
                                        PaintAlgorithm algorithm2,
                                        int width1,
                                        int width2,
                                        int height1,
                                        int height2)

Returns a cross hatch pattern.

The algorithms are applied to the cells as follows:

    algorithm1    algorithm1
    algorithm1    algorithm2
 

The cell widths and heights use the given values.

The x period is width1 + width2.

The y period is height1 + height2.

If either algorithm is null, returns null.

Parameters:
algorithm1 - the algorithm for 3 of 4 cells
algorithm2 - the algorithm for 1 of 4 cells
width1 - the width of column 1
width2 - the width of column 2
height1 - the height of row 1
height2 - the height of row 2
Returns:
a paint algorithm for the cross hatch

crossHatchDiagonal

public static PaintAlgorithm crossHatchDiagonal(Color color1,
                                                Color color2,
                                                int width1,
                                                int width2,
                                                int height1,
                                                int height2)

Equivalent to turn45(crossHatch(args)).


crossHatchDiagonal

public static PaintAlgorithm crossHatchDiagonal(PaintAlgorithm algorithm1,
                                                PaintAlgorithm algorithm2,
                                                int width1,
                                                int width2,
                                                int height1,
                                                int height2)

Equivalent to turn45(crossHatch(args)).


dottedGrid

public static PaintAlgorithm dottedGrid(Color dotColor,
                                        Color backColor,
                                        int dotSize,
                                        int gridSize)

Returns a dotted grid pattern with the given dot color and background color.

If null, the dot color is forced to black and the background color to white.

The dot size is forced to at least 1.

If necessary, the grid size is forced upward to be a multiple of twice the dot size.

The x and y periods equal the adjusted grid size.

Parameters:
dotColor - the dot color
backColor - the background color
dotSize - the dot size
gridSize - the size of the dot grid
Returns:
a paint algorithm for the dotted grid

dottedGridDiagonal

public static PaintAlgorithm dottedGridDiagonal(Color dotColor,
                                                Color backColor,
                                                int dotSize,
                                                int gridSize)

Equivalent to turn45(dottedGrid(args)).


brickEtoW

public static PaintAlgorithm brickEtoW(Color cellColor,
                                       Color edgeColor,
                                       int size)

Returns a brick pattern oriented horizontally (EW) such that the brick cell has dimensions width = 2 * size, height = size and uses the given cell color and edge color.

If null, the cell color is forced to brown, that is, R = 165, G = 42, B = 42.

If null, the edge color is forced to black.

The size is forced to at least 2.

The x and y periods equal 2 * size + 4 to allow space for the edges.

Parameters:
cellColor - the color that fills the brick
edgeColor - the color that outlines the brick
size - the quantity that determines the brick dimensions
Returns:
a paint algorithm for the brick

brickNEtoSW

public static PaintAlgorithm brickNEtoSW(Color cellColor,
                                         Color edgeColor,
                                         int size)

Equivalent to turn45(brickEtoW(args)).


brickNtoS

public static PaintAlgorithm brickNtoS(Color cellColor,
                                       Color edgeColor,
                                       int size)

Equivalent to turn90(brickEtoW(args)).


brickNWtoSE

public static PaintAlgorithm brickNWtoSE(Color cellColor,
                                         Color edgeColor,
                                         int size)

Equivalent to turn135(brickEtoW(args)).