Tuesday, May 8, 2012

creating silkscreen prints of common images 'java'

//creating silkscreen prints of common images
//you are to be inspired by Andy Warhol to create a collage of at least 4
 //different versions of the same original image.
 //At least two of the versions are to be posterizations using different final colors.
 //The other versions of the image can be done in anyway you like as long as they are not the same.
 //The different versions must be displayed in some grid format of at least size of 2x2 pictures.
 //The code for each version must be written in its own method.



import java.awt.Color;

public class Project3
{
public static void main(String[] args)

{

System.out.println("Begin Java Execution");
System.out.println("");

// put your Java Program here
// Prompt the user for a file

String filename;
filename = FileChooser.pickAFile();
System.out.println("Filename: " + filename);
Picture p = new Picture(filename);

int wid = p.getWidth();
int hgt = p.getHeight();

  System.out.println("The picture is " + wid + " pixels wide and " + hgt
+ " pixel high.");

Picture p2;
p2 = copiedPic(p);
//show the image
//p2.explore ();
p2.show();
System.out.println("");
System.out.println("End Java Execution");
}

// method to make copy from a picture and posterized it

public static Picture copiedPic(Picture p) {

int xPos, yPos;

int wid = p.getWidth();
int hgt = p.getHeight();

Picture result = new Picture(wid * 3, hgt * 2);

// loop for all the x values
for (xPos = 0; xPos < wid; ++xPos) {
// loop for the the Y values
for (yPos = 0; yPos < hgt; ++yPos)

{

// access a pixel and its color
Pixel pix = p.getPixel(xPos, yPos);
Color c1 = pix.getColor();

// store the color information into the resulting picture
Pixel pix1, pix2, pix3, pix4, pix5, pix6;


pix1 = result.getPixel(xPos, yPos);
pix1.setColor(c1);

pix2 = result.getPixel(xPos, yPos);
pix2.setColor(c1);

pix2 = result.getPixel(xPos + 2 * wid, yPos);
pix2.setColor(c1);

pix6 = result.getPixel(xPos, yPos);
pix6.setColor(c1);

pix6 = result.getPixel(xPos + 2 * wid, yPos + hgt);
pix6.setColor(c1);

pix3 = result.getPixel(xPos, yPos);
pix3.setColor(c1);

pix3 = result.getPixel(xPos, yPos + hgt);
pix3.setColor(c1);

pix4 = result.getPixel(xPos, yPos);
pix4.setColor(c1);

pix4 = result.getPixel(wid + xPos, yPos + hgt);
pix4.setColor(c1);

pix5 = result.getPixel(xPos, yPos);
pix5.setColor(c1);

pix5 = result.getPixel(wid + xPos, yPos);
pix5.setColor(c1);

// access the color values of that pixel
int red = pix3.getRed();
int green = pix3.getGreen();
int blue = pix3.getBlue();

// modify the color values of the pixel
int grayAmount;
grayAmount = (int) Math.round((red * 0.299) + (green * 0.587)
+ (blue * 0.114));

computeImage1(grayAmount, pix3); //calls the method to generate image 1 and sends the grayamount and the pixel to it
computeImage2(grayAmount, pix4);
computeImage3(grayAmount, pix5);
computeImage4(grayAmount, pix1);
computeImage5(grayAmount, pix2);
computeImage6(grayAmount, pix6);

}
}
return result;
}
// Start method computeImage set colors for the first Image.
public static void computeImage1(int grayAmount, Pixel pix3) {
int red;
int green;
int blue;

if (grayAmount < 128) {
red = 100;
green = 230;
blue = 34;
} else {
red = 200;
green = 105;
blue = 80;
}

// restore the color value of the pixel
pix3.setRed(red);
pix3.setGreen(green);
pix3.setBlue(blue);
} // End method
// Start method computeImage2 set colors for the second Image.
public static void computeImage2(int grayAmount, Pixel pix4) {
int red;
int green;
int blue;

if (grayAmount < 128) {
red = 100;
green = 50;
blue = 250;
} else {
red = 0;
green = 0;
blue = 0;
}
pix4.setRed(red);
pix4.setGreen(green);
pix4.setBlue(blue);
} //End Method
// Start method computeImage3 set colors for the third Image.
public static void computeImage3(int grayAmount, Pixel pix5) {
int red;
int green;
int blue;

if (grayAmount < 128) {
red = 100;
green = 50;
blue = 250;
} else {
red = 10;
green = 255;
blue = 127;
}
pix5.setRed(red);
pix5.setGreen(green);
pix5.setBlue(blue);
} //End method
// Start method computeImage4 set colors for the fourth Image.
public static void computeImage4(int grayAmount, Pixel pix1) {
int red;
int green;
int blue;

if (grayAmount < 128) {
red = 255;
green = 254;
blue = 102;
} else {
red = 177;
green = 101;
blue = 255;
}
pix1.setRed(red);
pix1.setGreen(green);
pix1.setBlue(blue);
} //End method
// Start method computeImage5 set colors for the Five Image.
public static void computeImage5(int grayAmount, Pixel pix2) {
int red;
int green;
int blue;

if (grayAmount < 128) {
red = 254;
green = 103;
blue = 103;
} else {
red = 104;
green = 254;
blue = 104;
}

pix2.setRed(red);
pix2.setGreen(green);
pix2.setBlue(blue);
} //End method
// Start method computeImage6 set colors for the six Image.
public static void computeImage6(int grayAmount, Pixel pix6) {
int red;
int green;
int blue;

if (grayAmount < 128) {
red = 255;
green = 27;
blue = 139;
} else {
red = 104;
green = 104;
blue = 254;
}
pix6.setRed(red);
pix6.setGreen(green);
pix6.setBlue(blue);
} //End method

}// end of Template class

No comments:

Post a Comment