0% found this document useful (0 votes)
9 views4 pages

Pixel

The document contains Java code for an 'Asphalt Art Project' that processes images to calculate average colors in specified regions. It includes methods for manipulating pixel data and generating a color set based on the image dimensions. Additionally, it features a custom 'ImagePlus' class that extends image functionality with pixel manipulation methods.

Uploaded by

anyuse51234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Pixel

The document contains Java code for an 'Asphalt Art Project' that processes images to calculate average colors in specified regions. It includes methods for manipulating pixel data and generating a color set based on the image dimensions. Additionally, it features a custom 'ImagePlus' class that extends image functionality with pixel manipulation methods.

Uploaded by

anyuse51234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

//cars.

add(0, "Mazda"); // Insert element at the beginning of the list (0)


//cars.set(0, "Opel"); change an item
//cars.clear();
/*test.move();
test.paint(test.convertRGBtoHex(255, 255, 255));
test.move();
test.move();*/
}
}
/*
import acm.program.*;
import java.util.*;
import acm.graphics.*;

public class Asphalt_Art_Project extends GraphicsProgram{//Easy Graphics


public static GImage image = new GImage("Luff.jpg");//Image of choice
public static int APPLICATION_WIDTH = (int) image.getWidth();
public static int APPLICATION_HEIGHT = (int) image.getHeight();

public String average(double x, double y, double wid, double hei) {


int red = 0, green = 0, blue = 0, total = 0;
int[][] pixels = image.getPixelArray();
for (int row=(int)x;row<x+wid;row++) {
for (int col=(int)y;col<y+hei;col++) {
int pixel = pixels[col][row];
red += GImage.getRed(pixel);
green += GImage.getGreen(pixel);
blue += GImage.getBlue(pixel);
total++;
//println(pixels[col][row]);
//println(row+" "+col);
}
}
String ncolor = "\""+(red/total)+"-"+(green/total)+"-"+(blue/total)
+'"';
return ncolor;
}

public void run() {


add(image);//Visuals
println(APPLICATION_WIDTH+" "+APPLICATION_HEIGHT);
ArrayList<String> color_set = new ArrayList<String>();
double roundOne = APPLICATION_WIDTH/32;
double roundTwo = APPLICATION_HEIGHT/32;
for (int i=0;i<32;i++) {
double part1 = roundOne * i;
for (int j=0;j<32;j++) {
double part2 = roundTwo * j;
//println(part1+","+part2+","+roundOne+","+roundTwo);
String ncolor = average(part1,part2,roundOne,roundTwo);
color_set.add(ncolor);
}
}
//Tell painter to go up to down move right
println(color_set);
}
}
*/
/*
import java.util.*;
import org.code.media.*;

public class Asphalt_Art_Project {//Easy Graphics


public static ImagePlus image = new ImagePlus("wordlegame.png");//Image of
choice
public static int APPLICATION_WIDTH = (int) image.getWidth();
public static int APPLICATION_HEIGHT = (int) image.getHeight();

public static String average(double x, double y, double wid, double hei) {


int red = 0, green = 0, blue = 0, total = 0;
Pixel [][] pixels = image.getPixels();
for (int row=(int)x;row<x+wid;row++) {
for (int col=(int)y;col<y+hei;col++) {
Pixel pixel = pixels[col][row];
red += pixel.getRed();
green += pixel.getGreen();
blue += pixel.getBlue();
total++;
//println(pixels[col][row]);
//println(row+" "+col);
}
}
String ncolor = "\""+(red/total)+"-"+(green/total)+"-"+(blue/total)
+'"';
return ncolor;
}

public static void main(String[] args) {


//add(image);//Visuals
System.out.println(APPLICATION_WIDTH+" "+APPLICATION_HEIGHT);
ArrayList<String> color_set = new ArrayList<String>();
double roundOne = APPLICATION_WIDTH/32;
double roundTwo = APPLICATION_HEIGHT/32;
for (int i=0;i<32;i++) {
double part1 = roundOne * i;
for (int j=0;j<32;j++) {
double part2 = roundTwo * j;
//println(part1+","+part2+","+roundOne+","+roundTwo);
String ncolor = average(part1,part2,roundOne,roundTwo);
color_set.add(ncolor);
}
}
//Tell painter to go up to down move right
System.out.println(color_set);
}
}
*/

/*
import org.code.theater.*;
import org.code.media.*;

/*
* Represents an image that can be modified with filters and effects
*/
/*public class ImagePlus extends Image {

private Pixel[][] pixels; // The 2D array of pixels

/*
* Constructor to create an ImagePlus object
* with a specified file name
*/
/* public ImagePlus(String filename) {
super(filename); // calls the Image class constructor

// Initialize the pixels array by getting the pixels from the image
pixels = getPixels();
}

/*
* Constructor to create an ImagePlus object
* with a specified width and height
*/
/* public ImagePlus(int width, int height) {
super(width, height); // calls the Image class constructor

// Initialize the pixels array by getting the pixels from the image
pixels = getPixels();
}

/*
* Returns the pixels in the image as a 2D array of Pixel objects
*/
/* public Pixel[][] getPixels() {
// Level 2
// TO DO #1: Create and return a 2D array of Pixel objects that
// contains the pixels from the image.

Pixel[][] tempPixels = new Pixel[getHeight()][getWidth()];

for (int row = 0; row < tempPixels.length; row++) {


for (int col = 0; col < tempPixels[0].length; col++) {
tempPixels[row][col] = getPixel(col, row);
}
}

return tempPixels;
}

// Unit 5 Lesson 6 - Level 3a


public void zeroRed() {
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];

currentPixel.setRed(0);
}
}
}

// Unit 5 Lesson 6 - Level 3b


public void zeroBlue() {
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];

currentPixel.setBlue(0);
}
}
}

// Unit 5 Lesson 6 - Level 3c


public void zeroGreen() {
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];

currentPixel.setGreen(0);
}
}
}

// Unit 5 Lesson 6 - Level 3d


public void keepBlue() {
for (int row = 0; row < pixels.length; row++) {
for (int col = 0; col < pixels[0].length; col++) {
Pixel currentPixel = pixels[row][col];

currentPixel.setRed(0);
currentPixel.setGreen(0);
}
}
}
}
*/

You might also like