Class Picture

java.lang.Object
  extended by SimplePicture
      extended by Picture
All Implemented Interfaces:
DigitalPicture

public class Picture
extends SimplePicture

A class that represents a picture. This class inherits from SimplePicture and allows the student to add functionality to the Picture class. Copyright Georgia Institute of Technology 2004

Author:
Barbara Ericson ericson@cc.gatech.edu

Constructor Summary
Picture()
          Constructor that takes no arguments
Picture(int width, int height)
          Constructor that takes the width and height
Picture(Picture copyPicture)
          Constructor that takes a picture and creates a copy of that picture
Picture(String fileName)
          Constructor that takes a file name and creates the picture
 
Method Summary
 void addBox()
          Method to add a solid red rectangle to the current picture
static Picture addBoxToBeach()
          Method to add a solid red rectangle to the beach picture
 void blendPictures()
          Method to blend two sisters together onto the current picture
 Picture blendPictures(Picture sourcePict, double sourceAlpha)
          Method to blend two pictures, the current picture object and the passed sourcePict object.
 void blueChange()
          Method to set all blue values to 100 in the picture
 void blueOneHundred()
          Method to set the blue values to 100 in a rectangle of 100 pixels with x and y starting at 0 and ending at 99
 void blur(int numPixels)
          Method to blur the pixels
 void changeColors(double redAmount, double greenAmount, double blueAmount)
          Method to change the color of each pixel in the picture object by passed in amounts.
 void changePixelsWithinDistance(Color compareColor, double distance, double redFactor, double greenFactor, double blueFactor, int startX, int startY, int endX, int endY)
          Method to change all the pixels within a passed distance of a passed color in a range specified by a startX, startY, endX, and endY by passed red, green, and blue factors.
 void changeRed(double amount)
          Method to change the red by an amount
 void changeRedAndGreen(double redMult, double greenMult)
          Method to change the red and green values in the current picture
 void chromakey(Picture newBg)
          Method to do chromakey using a blue background
 void chromakey(Picture newBg, Color color, double dist)
          Method to do chromakey using the passed background color and the distance to the color
 void chromakeyBlue(Picture newBg)
          Method to do chromakey using a blue background
 void chromakeyRed(Picture newBg)
          Method to do chromakey using a red background
 void clearBlue()
          Method to clear the blue from the picture (set the blue to 0 for all pixels)
 void clearBlue2()
          Method to clear the blue from the picture (set the blue to 0 for all pixels)
 void clearBlue3()
          Method to clear the blue from the picture (set the blue to 0 for all pixels)
 void clearSomeBlue()
          Method to set the blue to zero if the distance from this color to blue is greater than 100
 Picture clipToEllipse()
          Method to clip the picture to an ellipse
 Picture clipToMessage(String message)
          Method to create a new picture from this picture that shows the part of the current picture that is inside a text message
 void copy(Picture source, int x, int y)
          Method to copy the passed picture into the current picture at the given x and y position in the current picture
 void copy(Picture sourcePicture, int startX, int startY, int endX, int endY, int targetStartX, int targetStartY)
          Method to copy from the passed source picture to the current picture object The copying will start at startX, startY, and end at endX-1 and endY-1 The copy will be placed starting at targetStartX, targetStartY
 void copy2D(Picture source, int x, int y)
          Method to copy the passed picture into the current picture at the given x and y position in the current picture
 void copyFlowerLarger()
          Method to copy a flower but scaled to 2x normal size onto the current picture
 void copyFlowers()
          Method to copy flower pictures to create a collage.
 void copyFlowersBetter()
          Method to copy two flowers in a pattern to the bottom (5 pixels from bottom) of the current picture
 void copyFlowerSmaller()
          Method to copy the flower but smaller (half as big) on to the current picture
 void copyJakitaSmaller()
          Method to copy the picture of Jakita but smaller (half as big) to the current picture
 void copyKatie()
          Method to copy the picture of Katie to the upper left corner of the current picture
 void copyKatieLeftRotation()
          Method to copy the picture of Katie but rotate her left 90 degrees on the current picture
 void copyKatieMidway()
          Method to copy the picture of Katie to (100,100) in the current picture
 void copyKatiesFace()
          Method to copy just Katie's face to the current picture
 void copyNonWhitePixels(Picture sourcePicture, int startX, int startY, int endX, int endY, int targetStartX, int targetStartY)
          Method to copy from the passed source picture to the current picture object The copying will start at startX, startY, and end at endX-1 and endY-1 The copy will be placed starting at targetStartX, targetStartY
 void copyPicture(Picture sourcePict, Rectangle sourceRect, Rectangle targetRect, Composite composite)
          Method to copy a picture into the current picture using the passed composite rule
 void copyPictureTo(Picture sourcePicture, int xStart)
          Method that will copy all of the passed source picture into the current picture object starting with the left corner given by xStart.
 void copyPictureTo(Picture sourcePicture, int xStart, int yStart)
          Method that will copy all of the passed source picture into the current picture object starting with the left corner given by xStart, yStart
 void copyRobot()
          Method to copy the picture of a robot to the 100,100 of the current picture
 int countWhitePixels()
          Method to count the number of white pixels in a picture
static Picture createComposite()
          Method to try different composite rules in a picture with a gradient painted rectangle and a texture painted ellipse
 void darken()
          Method to darken the color in the picture
 void decreaseBlue()
          Method to decrease the blue in the picture by 30%
 void decreaseGreen()
          Method to decrease the green in the picture by 30%
 void decreaseRed()
          Method to decrease the red by half in the current picture
 Picture decreaseRedI()
          Method to decrease the red by half in a copy of the current picture
 void doubleRedInRange(int startX, int startY, int endX, int endY, double distance, Color compareColor)
          Method to double the red in a picture in a rectangular area if it is less than the passed distance to the passed color
 void drawBox(Color color, int topLeftX, int topLeftY, int width, int height)
          Method to draw a filled box on the current picture
 void drawExample()
          Method to show different drawing capabilities.
 void drawFace()
          Method to draw a face to demonstrate drawing ovals and arcs
 void drawFilledRectangles()
          Method to draw a picture with a succession of filled rectangles with the top left corner the darkest and the bottom right the lightest on the current picture
 void drawGrayEffect()
          Method to draw a gray effect picture on the current picture
 void drawGrid()
          Method to draw a grid on a picture
 void drawHorizontalCenteredString(String text, int y)
          Method to draw a horizontally centered string on the current picture
 void drawRectangles()
          Method to draw a picture with a succession of rectangles on the current picture
 void drawString(String text, int x, int y)
          Method to draw a string on the current picture
 void drawSun(int x, int y, int width, int height)
          Method to add a gradient painted sun to the current picture
 void drawWideX(Color color, float width)
          Method to add two crossed lines to a picture.
 void drawX(Color color)
          Method to add two crossed lines to a picture.
 void edgeDetection(double amount)
          Method to do a simple edge detection by comparing the absolute value of the difference between the color intensities (average of the color values) between a pixel and the pixel below it.
 void grayscale()
          Method to change the picture to gray scale
 void grayscaleWithLuminance()
          Method to change the picture to gray scale with luminance
 void highlightLightAndDark(double amount, Color replacementColor)
          Method to replace the pixel colors in the current picture object that have a color distance less than the passed amount to white or black with the passed replacement color
 void increaseRed()
          Method to increase the amount of red by 30%
 void increaseRed2()
          Method to increase the amount of red by 1.3 in the current picture
 void increaseRed3()
          Method to increase the amount of red by 1.3 in the current picture
 void lighten()
          Method to lighten the colors in the picture
 void lighten(Color compColor, double distance, int numTimes)
          Method to lighten the colors in the picture if the distance to the passed color is within the passed distance
 void makeSunset()
          Method to simulate a sunset by decreasing the green and blue
 void makeSunset(double reduction)
          Method to simulate a sunset by decreasing the green and blue
 void makeSunset2()
          Method to make a picture look like it was taken at sunset by reducing the blue and green to make it look more red
static void makeTurtleMovie()
          Method to show a turtle crawling across the beach
 void mirrorHorizontal()
          Method to mirror around a horizontal line in the middle based on the height.
 void mirrorHorizontalBottomToTop()
          Method to mirror around a horiztonal line in the middle based on the height of the picture.
 void mirrorTemple()
          Method to mirror part of the temple picture around a vertical line at a mirror point
static Picture mirrorTempleS3()
          Method to mirror the piedmont of the temple
 void mirrorVertical()
          Method to mirror around a vertical line in the middle of the picture based on the width
 void negate()
          Method to negate the picture
 void overlapPictures(Picture p1, Picture p2, int startOverlap)
          Method to overlap one picture with another horizontally on top of the current picture.
static Picture pickAndShow()
          Method to allow the user to pick a file name and show a picture.
 void posterize()
          Method to posterize (reduce the number of colors) in the picture.
 void posterize(int numLevels)
          Method to posterize (reduce the number of colors) in the picture
 void removeRedEye(int startX, int startY, int endX, int endY, Color newColor)
          Method to remove red eye from the current picture object in the rectangle defined by startX, startY, endX, endY.
 Picture rotate(int degrees)
          Method to create a new picture by rotating the current picture by the given degrees
 Picture scale(double xFactor, double yFactor)
          Method to create a new picture by scaling the current picture by the given x and y factors
 Picture scaleUp(int numTimes)
          Method to create a new picture that is scaled up by the passed number of times.
 void sepiaTint()
          Method to change the current picture to a sepia tint (modify the middle colors to a light brown and the light colors to a light yellow and make the shadows darker)
 void setBlue()
          Method to set the blue to zero if the current blue value is greater than 100
 void setRedToBlue()
          Method to set the red to the blue value
 Picture shear(double xFactor, double yFactor)
          Method to create a new picture by shearing the current picture by the given x and y factors
static Picture showNamed(String fileName)
          Method to show a picture created from a passed file name
static Picture showSpecificPicture()
          Method to show a specific picture where the file name to show is specified in the method.
static void showTurtleMovie()
          Method to show a turtle crawling across the beach
 void swapBackground(Picture oldBackground, Picture newBackground)
          Method to replace the background in the current picture with the background from another picture
 void swapBackground(Picture oldBackground, Picture newBackground, double threshold)
          Method to replace the background in the current picture with the background from another picture
 String toString()
          Method to return a string with information about this picture.
 void turnBrownIntoRed()
          Method to turn the brown in a picture into red
 void turnBrownToRedInRectangle()
          Method to turn brown to red inside of a rectangular area
 void turnBrownToRedInRectangle(int startX, int endX, int startY, int endY)
          Method to turn brown to red in a rectangular area specifed by startX, endX-1, startY, endY-1
 void turnBrownToRedInRectangle(int startX, int endX, int startY, int endY, double distance)
          Method to turn brown to red in a rectangular area specifed by startX, endX-1, startY, endY-1
 
Methods inherited from class SimplePicture
addMessage, copyPicture, createGraphics, explore, getBasicPixel, getBufferedImage, getExtension, getFileName, getGraphics, getHeight, getImage, getMediaPath, getPictureFrame, getPictureWithHeight, getPixel, getPixels, getTitle, getTransformEnclosingRect, getWidth, hide, load, load, loadPictureAndShowIt, repaint, setAllPixelsToAColor, setBasicPixel, setMediaPath, setPictureFrame, setTitle, setVisible, show, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Picture

public Picture()
Constructor that takes no arguments


Picture

public Picture(String fileName)
Constructor that takes a file name and creates the picture

Parameters:
fileName - the name of the file to create the picture from

Picture

public Picture(int width,
               int height)
Constructor that takes the width and height

Parameters:
width - the width of the desired picture
height - the height of the desired picture

Picture

public Picture(Picture copyPicture)
Constructor that takes a picture and creates a copy of that picture

Method Detail

toString

public String toString()
Method to return a string with information about this picture.

Overrides:
toString in class SimplePicture
Returns:
a string with information about the picture such as fileName, height, and width.

pickAndShow

public static Picture pickAndShow()
Method to allow the user to pick a file name and show a picture. This method will also return the created picture object.

Returns:
the picture object created from the picked file name

showSpecificPicture

public static Picture showSpecificPicture()
Method to show a specific picture where the file name to show is specified in the method. To change which picture you want to show you can edit the method and recompile it.

Returns:
the created picture object

showNamed

public static Picture showNamed(String fileName)
Method to show a picture created from a passed file name

Parameters:
fileName - the name of the file to create the picture from
Returns:
the created picture object

decreaseRedI

public Picture decreaseRedI()
Method to decrease the red by half in a copy of the current picture

Returns:
a copy of the current picture with the red decreased by half

decreaseRed

public void decreaseRed()
Method to decrease the red by half in the current picture


setRedToBlue

public void setRedToBlue()
Method to set the red to the blue value


changeRedAndGreen

public void changeRedAndGreen(double redMult,
                              double greenMult)
Method to change the red and green values in the current picture

Parameters:
redMult - the amount to multiply the red by
greenMult - the amount to multiply the green by

increaseRed

public void increaseRed()
Method to increase the amount of red by 30%


clearBlue

public void clearBlue()
Method to clear the blue from the picture (set the blue to 0 for all pixels)


makeSunset

public void makeSunset()
Method to simulate a sunset by decreasing the green and blue


makeSunset

public void makeSunset(double reduction)
Method to simulate a sunset by decreasing the green and blue

Parameters:
reduction - the amount to multiply the original values by

decreaseGreen

public void decreaseGreen()
Method to decrease the green in the picture by 30%


decreaseBlue

public void decreaseBlue()
Method to decrease the blue in the picture by 30%


makeSunset2

public void makeSunset2()
Method to make a picture look like it was taken at sunset by reducing the blue and green to make it look more red


changeRed

public void changeRed(double amount)
Method to change the red by an amount

Parameters:
amount - the amount to change the red by

changeColors

public void changeColors(double redAmount,
                         double greenAmount,
                         double blueAmount)
Method to change the color of each pixel in the picture object by passed in amounts.

Parameters:
redAmount - the amount to change the red value
greenAmount - the amount to change the green value
blueAmount - the amount to change the blue value

clearBlue2

public void clearBlue2()
Method to clear the blue from the picture (set the blue to 0 for all pixels)


clearBlue3

public void clearBlue3()
Method to clear the blue from the picture (set the blue to 0 for all pixels)


darken

public void darken()
Method to darken the color in the picture


negate

public void negate()
Method to negate the picture


grayscale

public void grayscale()
Method to change the picture to gray scale


grayscaleWithLuminance

public void grayscaleWithLuminance()
Method to change the picture to gray scale with luminance


increaseRed2

public void increaseRed2()
Method to increase the amount of red by 1.3 in the current picture


increaseRed3

public void increaseRed3()
Method to increase the amount of red by 1.3 in the current picture


lighten

public void lighten()
Method to lighten the colors in the picture


lighten

public void lighten(Color compColor,
                    double distance,
                    int numTimes)
Method to lighten the colors in the picture if the distance to the passed color is within the passed distance

Parameters:
compColor - the color to compare to
distance - the distance from the compare color
numTimes - the number of times to lighten

mirrorVertical

public void mirrorVertical()
Method to mirror around a vertical line in the middle of the picture based on the width


mirrorHorizontal

public void mirrorHorizontal()
Method to mirror around a horizontal line in the middle based on the height. It copies the top mirrored to the bottom


mirrorHorizontalBottomToTop

public void mirrorHorizontalBottomToTop()
Method to mirror around a horiztonal line in the middle based on the height of the picture. It copies the bottom to the top.


mirrorTemple

public void mirrorTemple()
Method to mirror part of the temple picture around a vertical line at a mirror point


mirrorTempleS3

public static Picture mirrorTempleS3()
Method to mirror the piedmont of the temple

Returns:
the corrected picture

copyKatie

public void copyKatie()
Method to copy the picture of Katie to the upper left corner of the current picture


copyRobot

public void copyRobot()
Method to copy the picture of a robot to the 100,100 of the current picture


copyKatieMidway

public void copyKatieMidway()
Method to copy the picture of Katie to (100,100) in the current picture


copyKatiesFace

public void copyKatiesFace()
Method to copy just Katie's face to the current picture


copyFlowers

public void copyFlowers()
Method to copy flower pictures to create a collage. All the flower pictures will be lined up near the bottom of the current picture (5 pixels from the bottom)


copyPictureTo

public void copyPictureTo(Picture sourcePicture,
                          int xStart)
Method that will copy all of the passed source picture into the current picture object starting with the left corner given by xStart. It will put the sourcePicture at 5 pixels from the bottom of this picture

Parameters:
sourcePicture - the picture object to copy
xStart - the x position to start the copy in the target

copyFlowersBetter

public void copyFlowersBetter()
Method to copy two flowers in a pattern to the bottom (5 pixels from bottom) of the current picture


copy

public void copy(Picture sourcePicture,
                 int startX,
                 int startY,
                 int endX,
                 int endY,
                 int targetStartX,
                 int targetStartY)
Method to copy from the passed source picture to the current picture object The copying will start at startX, startY, and end at endX-1 and endY-1 The copy will be placed starting at targetStartX, targetStartY

Parameters:
sourcePicture - the source picture to copy from
startX - the starting x value in the source picture
startY - the starting y value in the source picture
endX - the ending x value in the source picture
endY - the ending y value in the source picture
targetStartX - the starting x value in the current picture
targetStartY - the starting y value in the current picture

copyNonWhitePixels

public void copyNonWhitePixels(Picture sourcePicture,
                               int startX,
                               int startY,
                               int endX,
                               int endY,
                               int targetStartX,
                               int targetStartY)
Method to copy from the passed source picture to the current picture object The copying will start at startX, startY, and end at endX-1 and endY-1 The copy will be placed starting at targetStartX, targetStartY

Parameters:
sourcePicture - the source picture to copy from
startX - the starting x value in the source picture
startY - the starting y value in the source picture
endX - the ending x value in the source picture
endY - the ending y value in the source picture
targetStartX - the starting x value in the current picture
targetStartY - the starting y value in the current picture

blendPictures

public void blendPictures()
Method to blend two sisters together onto the current picture


copyPictureTo

public void copyPictureTo(Picture sourcePicture,
                          int xStart,
                          int yStart)
Method that will copy all of the passed source picture into the current picture object starting with the left corner given by xStart, yStart

Parameters:
sourcePicture - the picture object to copy
xStart - the x position to start the copy into on the target
yStart - the y position to start the copy into on the target

copyKatieLeftRotation

public void copyKatieLeftRotation()
Method to copy the picture of Katie but rotate her left 90 degrees on the current picture


copyFlowerSmaller

public void copyFlowerSmaller()
Method to copy the flower but smaller (half as big) on to the current picture


copyJakitaSmaller

public void copyJakitaSmaller()
Method to copy the picture of Jakita but smaller (half as big) to the current picture


copyFlowerLarger

public void copyFlowerLarger()
Method to copy a flower but scaled to 2x normal size onto the current picture


turnBrownIntoRed

public void turnBrownIntoRed()
Method to turn the brown in a picture into red


turnBrownToRedInRectangle

public void turnBrownToRedInRectangle()
Method to turn brown to red inside of a rectangular area


turnBrownToRedInRectangle

public void turnBrownToRedInRectangle(int startX,
                                      int endX,
                                      int startY,
                                      int endY)
Method to turn brown to red in a rectangular area specifed by startX, endX-1, startY, endY-1

Parameters:
startX - the starting location to check in x
endX - the last pixel checked is one less than this in x
startY - the starting location to check in y
endY - the last pixel checked is one less than this in y

turnBrownToRedInRectangle

public void turnBrownToRedInRectangle(int startX,
                                      int endX,
                                      int startY,
                                      int endY,
                                      double distance)
Method to turn brown to red in a rectangular area specifed by startX, endX-1, startY, endY-1

Parameters:
startX - the starting location to check in x
endX - the last pixel checked is one less than this in x
startY - the starting location to check in y
endY - the last pixel checked is one less than this in y
distance - if the current color is within this distance to brown then change it

doubleRedInRange

public void doubleRedInRange(int startX,
                             int startY,
                             int endX,
                             int endY,
                             double distance,
                             Color compareColor)
Method to double the red in a picture in a rectangular area if it is less than the passed distance to the passed color

Parameters:
startX - the x value at the top left of the rectangular area
startY - the y value at the top left of the rectangular area
endX - the bottom right x value of the rectangular area
endY - the bottom right y value of the rectangular area
distance - the amount that the distance must be less than
compareColor - the color to compare the current pixel color to

changePixelsWithinDistance

public void changePixelsWithinDistance(Color compareColor,
                                       double distance,
                                       double redFactor,
                                       double greenFactor,
                                       double blueFactor,
                                       int startX,
                                       int startY,
                                       int endX,
                                       int endY)
Method to change all the pixels within a passed distance of a passed color in a range specified by a startX, startY, endX, and endY by passed red, green, and blue factors.

Parameters:
compareColor - the color to compare to
distance - the distance that this should be within (less than)
redFactor - the amount to multiply the current red value by
greenFactor - the amount to multiply the current green value by
blueFactor - the amount to multiply the current blue value by
startX - the starting x value to use in checking the pixels
startY - the starting y value to use in checking the pixels
endX - the ending x value to use in checking the pixels (< this)
endY - the ending y value to use in checking the pixels (< this)

removeRedEye

public void removeRedEye(int startX,
                         int startY,
                         int endX,
                         int endY,
                         Color newColor)
Method to remove red eye from the current picture object in the rectangle defined by startX, startY, endX, endY. The red will be replaced with the passed newColor

Parameters:
startX - the top left corner x value of a rectangle
startY - the top left corner y value of a rectangle
endX - the bottom right corner x value of a rectangle
endY - the bottom right corner y value of a rectangle
newColor - the new color to use

sepiaTint

public void sepiaTint()
Method to change the current picture to a sepia tint (modify the middle colors to a light brown and the light colors to a light yellow and make the shadows darker)


posterize

public void posterize()
Method to posterize (reduce the number of colors) in the picture. The number of reds, greens, and blues will be 4


posterize

public void posterize(int numLevels)
Method to posterize (reduce the number of colors) in the picture

Parameters:
numLevels - the number of color levels to use

highlightLightAndDark

public void highlightLightAndDark(double amount,
                                  Color replacementColor)
Method to replace the pixel colors in the current picture object that have a color distance less than the passed amount to white or black with the passed replacement color

Parameters:
replacementColor - the new color to use

scaleUp

public Picture scaleUp(int numTimes)
Method to create a new picture that is scaled up by the passed number of times.

Returns:
the new scaled up picture

blur

public void blur(int numPixels)
Method to blur the pixels

Parameters:
numPixels - the number of pixels to average in all directions. So if the numPixels is 2 then we will average all pixels in the rectangle defined by 2 before the current pixel to 2 after the current pixel

edgeDetection

public void edgeDetection(double amount)
Method to do a simple edge detection by comparing the absolute value of the difference between the color intensities (average of the color values) between a pixel and the pixel below it. If the absolute value of the difference between the color intensities is less than a passed amount the top pixel color will be set to white. Otherwise it is set to black.

Parameters:
amount - if the absolute value of the differences in the color average is less than this set the color to white, else black

swapBackground

public void swapBackground(Picture oldBackground,
                           Picture newBackground)
Method to replace the background in the current picture with the background from another picture

Parameters:
oldBackground - the old background to replace
newBackground - the new background to use

swapBackground

public void swapBackground(Picture oldBackground,
                           Picture newBackground,
                           double threshold)
Method to replace the background in the current picture with the background from another picture

Parameters:
oldBackground - the old background to replace
newBackground - the new background to use
threshold - if the distance between the current pixel color and the background pixel color is less than this amount use the new background pixel color

chromakey

public void chromakey(Picture newBg,
                      Color color,
                      double dist)
Method to do chromakey using the passed background color and the distance to the color

Parameters:
newBg - the new background image to use to replace
color - the background color to compare to
dist - the distance that limits the chromakey it will happen if the distance is less than or equal to this value

chromakey

public void chromakey(Picture newBg)
Method to do chromakey using a blue background

Parameters:
newBg - the new background image to use to replace the blue from the current picture

chromakeyBlue

public void chromakeyBlue(Picture newBg)
Method to do chromakey using a blue background

Parameters:
newBg - the new background image to use to replace the blue from the current picture

chromakeyRed

public void chromakeyRed(Picture newBg)
Method to do chromakey using a red background

Parameters:
newBg - the new background image to use to replace the red from the current picture

blueOneHundred

public void blueOneHundred()
Method to set the blue values to 100 in a rectangle of 100 pixels with x and y starting at 0 and ending at 99


blueChange

public void blueChange()
Method to set all blue values to 100 in the picture


clearSomeBlue

public void clearSomeBlue()
Method to set the blue to zero if the distance from this color to blue is greater than 100


setBlue

public void setBlue()
Method to set the blue to zero if the current blue value is greater than 100


countWhitePixels

public int countWhitePixels()
Method to count the number of white pixels in a picture

Returns:
the number of white (r=255, g=255, b=255) pixels

drawGrid

public void drawGrid()
Method to draw a grid on a picture


addBox

public void addBox()
Method to add a solid red rectangle to the current picture


addBoxToBeach

public static Picture addBoxToBeach()
Method to add a solid red rectangle to the beach picture


drawBox

public void drawBox(Color color,
                    int topLeftX,
                    int topLeftY,
                    int width,
                    int height)
Method to draw a filled box on the current picture

Parameters:
color - the color to draw the box with
topLeftX - the top left x coordinate of the box
topLeftY - the top left y coordinate of the box
width - the width of the box
height - the height of the box

drawExample

public void drawExample()
Method to show different drawing capabilities. It will draw a string, a line, a filled rectangle, the outline of a rectangle, the outline of an oval, and a filled arc.


drawFace

public void drawFace()
Method to draw a face to demonstrate drawing ovals and arcs


drawString

public void drawString(String text,
                       int x,
                       int y)
Method to draw a string on the current picture

Parameters:
text - the string to draw
x - the x location to start at
y - the y location of the baseline

drawHorizontalCenteredString

public void drawHorizontalCenteredString(String text,
                                         int y)
Method to draw a horizontally centered string on the current picture

Parameters:
text - the string to draw
y - the y location of the baseline

drawGrayEffect

public void drawGrayEffect()
Method to draw a gray effect picture on the current picture


drawFilledRectangles

public void drawFilledRectangles()
Method to draw a picture with a succession of filled rectangles with the top left corner the darkest and the bottom right the lightest on the current picture


drawRectangles

public void drawRectangles()
Method to draw a picture with a succession of rectangles on the current picture


drawX

public void drawX(Color color)
Method to add two crossed lines to a picture. One line will go from the top left corner to the bottom right corner. The other will go from the bottom left corner to the top right corner.

Parameters:
color - the color to draw the x in

drawWideX

public void drawWideX(Color color,
                      float width)
Method to add two crossed lines to a picture. One line will go from the top left corner to the bottom right corner. The other will go from the bottom left corner to the top right corner.


rotate

public Picture rotate(int degrees)
Method to create a new picture by rotating the current picture by the given degrees

Parameters:
degrees - the number of degrees to rotate by
Returns:
the resulting picture

shear

public Picture shear(double xFactor,
                     double yFactor)
Method to create a new picture by shearing the current picture by the given x and y factors

Parameters:
xFactor - multiplier to use to shift in x direction based on y index
yFactor - multiplier to use to shift in y direction based on x index
Returns:
the resulting picture

scale

public Picture scale(double xFactor,
                     double yFactor)
Method to create a new picture by scaling the current picture by the given x and y factors

Parameters:
xFactor - the amount to scale in x
yFactor - the amount to scale in y
Returns:
the resulting picture

createComposite

public static Picture createComposite()
Method to try different composite rules in a picture with a gradient painted rectangle and a texture painted ellipse


copy

public void copy(Picture source,
                 int x,
                 int y)
Method to copy the passed picture into the current picture at the given x and y position in the current picture

Parameters:
source - the picture to copy
x - the x of the upper left corner to copy to
y - the y of the upper left corner to copy to

copy2D

public void copy2D(Picture source,
                   int x,
                   int y)
Method to copy the passed picture into the current picture at the given x and y position in the current picture

Parameters:
source - the picture to copy
x - the x of the upper left corner to copy to
y - the y of the upper left corner to copy to

overlapPictures

public void overlapPictures(Picture p1,
                            Picture p2,
                            int startOverlap)
Method to overlap one picture with another horizontally on top of the current picture. First the part of the first picture before the overlap will be displayed, next to that will be the overlapping region up to the end of the first picture, after that is the remainder of the second picture

Parameters:
p1 - the first picture to display
p2 - the second picture to display
startOverlap - the x position where the overlap begins

drawSun

public void drawSun(int x,
                    int y,
                    int width,
                    int height)
Method to add a gradient painted sun to the current picture

Parameters:
x - the x location for the upper left corner of the rectangle enclosing the sun
y - the y location for the upper left corner of the rectangle enclosing the sun
width - the width of the enclosing rectangle
height - the height of the enclosing rectangle

clipToEllipse

public Picture clipToEllipse()
Method to clip the picture to an ellipse

Returns:
a new picture with the image clipped to an ellipse

clipToMessage

public Picture clipToMessage(String message)
Method to create a new picture from this picture that shows the part of the current picture that is inside a text message

Parameters:
message - the message to show
Returns:
the new picture

blendPictures

public Picture blendPictures(Picture sourcePict,
                             double sourceAlpha)
Method to blend two pictures, the current picture object and the passed sourcePict object. The amount of the source picture to use is given in sourceAlpha. The amount of the current picture to use is (1.0 - sourceAlpha)

Parameters:
sourcePict - the source picture
sourceAlpha - the amount of the source picture to use
Returns:
the result of blending the source picture with the current picture object

copyPicture

public void copyPicture(Picture sourcePict,
                        Rectangle sourceRect,
                        Rectangle targetRect,
                        Composite composite)
Method to copy a picture into the current picture using the passed composite rule

Parameters:
sourcePict - the source picture to copy from
sourceRect - the rectangle that describes what area to copy from
targetRect - the rectangle that describes what area to copy into
composite - the composite to use

showTurtleMovie

public static void showTurtleMovie()
Method to show a turtle crawling across the beach


makeTurtleMovie

public static void makeTurtleMovie()
Method to show a turtle crawling across the beach