import java.awt.Color;
public class TestMethods
{
public static void main(String[] args)
{
Picture testPicture= new Picture(FileChooser.pickAFile());
testPicture.show();
Picture changedPic= testPicture.circleNegate(200,200,30);
changedPic.show();
}
}
//PICTURE CLASS
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.text.*;
/**
* 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-2005
* @author Barbara Ericson ericson@cc.gatech.edu
*/
public class Picture extends SimplePicture
{
///////////////////// constructors //////////////////////////////////
/**
* Constructor that takes no arguments
*/
public Picture ()
{
/* not needed but use it to show students the implicit call to super()
* child constructors always call a parent constructor
*/
super();
}
/**
* Constructor that takes a file name and creates the picture
* @param fileName the name of the file to create the picture from
*/
public Picture(String fileName)
{
// let the parent class handle this fileName
super(fileName);
}
/**
* Constructor that takes the width and height
* @param width the width of the desired picture
* @param height the height of the desired picture
*/
public Picture(int width, int height)
{
// let the parent class handle this width and height
super(width,height);
}
/**
* Constructor that takes a picture and creates a
* copy of that picture
*/
public Picture(Picture copyPicture)
{
// let the parent class do the copy
super(copyPicture);
}
////////////////////// methods ///////////////////////////////////////
/**
* Method to return a string with information about this picture.
* @return a string with information about the picture such as fileName,
* height and width.
*/
public String toString()
{
String output = "Picture, filename " + getFileName() +
" height " + getHeight()
+ " width " + getWidth();
return output;
}
public void changeRed(double howmuch)
{
Pixel[] pixelArray=this.getPixels();
Pixel pixelObj;
int index=0;
int value=0;
while(index<pixelArray.length)
{
pixelObj = pixelArray[index];
value=pixelObj.getRed();
value= (int)(value*howmuch);
pixelObj.setRed(value);
index++;
}
}
public Picture circleNegate(int centerx, int centery, int radius)
{
int x, y;
Pixel pixelObj;
for(y=centery-radius; y<=centery+radius; y++)
{
for(x = centerx-radius; x <= centerx+radius; x++)
{
if(Math.sqrt((int)((x-centerx)*(x-centerx) + (y-centery)*(y-centery))) <= radius)
{
pixelObj= this.getPixel(x,y);
pixelObj.setRed(255-pixelObj.getRed());
pixelObj.setBlue(255-pixelObj.getBlue());
pixelObj.setGreen(255-pixelObj.getGreen());
}
}
}
return this;
}
public Picture makeGreen()
{
Pixel pixelObj=null;
int index=0;
Pixel[] pixelArray= getPixels();
while (index< pixelArray.length)
{
pixelArray[index]=pixelObj;
pixelObj.setRed(pixelObj.getRed()/4);
pixelObj.setBlue(pixelObj.getBlue()/4);
pixelObj.setGreen(255);
index++;
}
return this;
}
public Picture mirrorHorizontal()
{
int midpoint=this.getHeight()/2;
Pixel topPixel, bottomPixel;
for(int y=0; y<midpoint; y++)
{
for(int x=0; x<this.getWidth(); x++)
{
topPixel=getPixel(x,y);
bottomPixel=getPixel(this.getWidth() - 1 - x,y);
bottomPixel.setColor(topPixel.getColor());
}
}
return this;
}
}