Advertisement
COS_HelpWithHomework

Comp008 - Lab 5: ClassExample_TestBlank.java

Oct 10th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import images.APImage;
  2. import images.Pixel;
  3. import java.util.Scanner;
  4.  
  5. public class TestBlank{
  6.  
  7.     public static void main(String[]args){
  8.         //Set up a scanner so that the program can read a blank line from the user
  9.         Scanner reader = new Scanner(System.in);
  10.  
  11.         //Create an image from the image package (note: there is something wrong with window
  12.         //the image appears in making it smaller than we want it to be the first time.  Set
  13.         //the size to 150 by 150 but it won't be until it is drawn again later.
  14.         APImage image = new APImage(150, 150);
  15.  
  16.         //Actually put up the blank black image
  17.         image.draw();
  18.  
  19.         //find the middle of the image
  20.         int y = image.getHeight()/2;
  21.  
  22.         //for that middle work across each pixel on the x axis and change it to red
  23.         for(int x = 0; x <= image.getWidth(); x++)
  24.                 image.setPixel(x, y, new Pixel(255, 0, 0));
  25.        
  26.         //Used to make the program wait to draw the red line
  27.         System.out.print("Press return to continue:");
  28.         reader.nextLine();
  29.        
  30.         //additional two lines that show where a pariticular pixel is so that you can judge the space
  31.         Pixel p = image.getPixel(99,99);
  32.         p.setGreen(255);
  33.        
  34.         //draw the image again so that there is a red line going through the middle and one green pixel
  35.         image.draw();
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement