Skip to content

Instantly share code, notes, and snippets.

@connlark
Last active November 16, 2015 04:15
Show Gist options
  • Save connlark/54e29dfd1b8f3cdfa2ac to your computer and use it in GitHub Desktop.
Save connlark/54e29dfd1b8f3cdfa2ac to your computer and use it in GitHub Desktop.
for the grags out there
/**
* Created by Connor on 11/4/15.
*/
public class MyArt {
private Picture image;
/**
* Create an Art object using the jpg or bmp at the indicated location
*/
public MyArt(String filename)
{
image = new Picture(filename);
}
/**
* Create the default Art object using kitten.jpg
*/
public MyArt()
{
image = new Picture("kitten.jpg");
}
/**
* Create a rectangular Art object with random color values
*/
public MyArt(int size)
{
int picSize = 0;
if(size < 100)
{
picSize = 100;
}
else
{
picSize = size;
}
image = new Picture(picSize, picSize*2);
//Picture colors values between 0 and 255
int red = (int)(Math.random()*256);
int green = (int)(Math.random()*256);
int blue = (int)(Math.random()*256);
for(int x = 0; x < image.getWidth(); x++)
{
for(int y = 0; y < image.getHeight(); y++)
{
Pixel pixelObj = image.getPixel(x, y);
pixelObj.setRed(red);
pixelObj.setGreen(green);
pixelObj.setBlue(blue);
}
}
}
/**
* Show the Art object
*/
public void show()
{
image.show();
}
public void reflect() {
Picture tempImg = new Picture(image.getWidth(),image.getHeight());
for(int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
int newX = (image.getWidth()-1) - x;
tempImg.setBasicPixel(newX,y,image.getBasicPixel(x,y));
}
}
image = tempImg;
}
public void swapColors(){
for(int x = 0; x < image.getWidth(); x++) {
for(int y = 0; y < image.getHeight(); y++) {
Pixel pixelObj = image.getPixel(x, y);
int newRed = pixelObj.getGreen();
int newGreen = pixelObj.getBlue();
int newBlue = pixelObj.getRed();
pixelObj.updatePicture(pixelObj.getAlpha(),newRed,newGreen,newBlue);
}
}
}
public void doubleHorizontal(){
Picture tempImg = new Picture(image.getWidth()*2,image.getHeight());
for(int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
tempImg.setBasicPixel(x,y,image.getBasicPixel(x,y));
tempImg.setBasicPixel(x + image.getWidth(),y,image.getBasicPixel(x,y));
}
}
image = tempImg;
}
public void doubleVertical(){
Picture tempImg = new Picture(image.getWidth(),image.getHeight()*2);
for(int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
tempImg.setBasicPixel(x,y,image.getBasicPixel(x,y));
tempImg.setBasicPixel(x,y + image.getHeight(),image.getBasicPixel(x,y));
}
}
image = tempImg;
}
public void border(){
int borderWidth = (int) (image.getWidth()*0.1);
int borderHeight = (int) (image.getHeight()*0.1);
Picture tempImg = new Picture(borderWidth + image.getWidth(), borderHeight + image.getHeight());
tempImg.setAllPixelsToAColor(java.awt.Color.black);
borderHeight /= 2; borderWidth /= 2;
for(int x = borderWidth; x < image.getWidth() + borderWidth; x++) {
for (int y = borderHeight; y < image.getHeight() + borderHeight; y++) {
tempImg.setBasicPixel(x,y,image.getBasicPixel((x-borderWidth),(y-borderHeight)));
}
}
image = tempImg;
}
public boolean equals(Object other){
if (!(other instanceof MyArt)){
return false;
}
MyArt otherArtObj = (MyArt) other;
Picture otherImg = otherArtObj.image;
if (otherImg.getHeight() != this.image.getHeight()) {
return false;
}
if (otherImg.getWidth() != this.image.getWidth()) {
return false;
}
for(int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
if (image.getBasicPixel(x,y) != otherImg.getBasicPixel(x,y)) return false;
}
}
return true;
}
public void masterpiece(){
Picture tempImg = new Picture(image.getWidth(),image.getHeight());
for(int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
int newX = (image.getWidth()-1) - x;
image.setBasicPixel(newX,y,image.getBasicPixel(x,y));
}
}
int randomNum = (int)(Math.random() * 100);
int randomNum1 = (int)(Math.random() * 100);
int randomNum2 = (int)(Math.random() * 100);
for(int x = 0; x < image.getWidth(); x++) {
for(int y = 0; y < image.getHeight(); y++) {
Pixel pixelObj = image.getPixel(x, y);
int newRed = pixelObj.getRed();
int newGreen = pixelObj.getGreen();
int newBlue = pixelObj.getBlue() - 100;
pixelObj.updatePicture(1,newRed,newGreen,newBlue);
}
}
int messages = (int)(Math.random() * 1000);
for (int i = 0; i < messages; i++) {
int randIntX = (int)(Math.random() * image.getWidth());
int randIntY = (int)(Math.random() * image.getHeight());
image.addMessage(".", randIntX,randIntY);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment