Advertisement
Guest User

1ª parte

a guest
Jan 26th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. import aguiaj.iscte.*;
  4.  
  5.  
  6. public class Parte1 {
  7.  
  8.     //Questao 1
  9.     public static ColorImage copy(ColorImage img){
  10.         ColorImage newImage = new ColorImage (img.getWidth(), img.getHeight());
  11.         for(int i = 0; i < img.getWidth(); i++){
  12.             for(int j = 0; j < img.getHeight(); j++){
  13.                 newImage.setColor(i, j, img.getColor(i,j));
  14.             }
  15.         }
  16.         return newImage;
  17.     }
  18.    
  19.     public static ColorImage copyWithMargin(ColorImage img, int margin){
  20.         ColorImage newImage = new ColorImage (img.getWidth(), img.getHeight());
  21.         newImage = copy(img);
  22.         Color white = new Color (255,255,255);
  23.         for(int i = 0; i < newImage.getWidth(); i++){
  24.             for(int j= 0; j < margin; j++){
  25.                 newImage.setColor(i, j, white);
  26.                 newImage.setColor(i, newImage.getHeight()-margin+j, white);
  27.             }
  28.         }
  29.         for(int i = 0; i < margin; i++){
  30.             for(int j= 0; j < newImage.getHeight(); j++){
  31.                 newImage.setColor(i, j, white);
  32.                 newImage.setColor(newImage.getWidth()-margin+i,j, white);
  33.             }
  34.         }
  35.         return newImage;
  36.     }
  37.    
  38.     //Questao 2
  39.     public static BinaryImage matrix (boolean [][] mat){
  40.         BinaryImage bin = new BinaryImage(mat.length, mat[0].length);
  41.         for(int i = 0; i < mat.length; i++){
  42.             for(int j = 0; j < mat[0].length; j++){
  43.                 if(mat[i][j] == true)
  44.                     bin.setBlack(i, j);
  45.                 else   
  46.                     bin.setWhite(i, j);
  47.             }
  48.            
  49.         }
  50.         return bin;
  51.     }
  52.    
  53.     //Cria uma matriz random para testar com o aguiaj
  54.     public static boolean [][] ma(int x){
  55.         boolean [][] mat = new boolean [x][x];
  56.         Random r = new Random();
  57.         for(int i = 0; i < x; i++){
  58.             for(int j=0; j < x; j++){
  59.                 mat[i][j] = r.nextBoolean();
  60.             }
  61.         }
  62.         return mat;
  63.     }
  64.    
  65.     //Questão 3
  66.     public static Color newColor(Color color, int peso){
  67.         int max = 255;
  68.         int r = 0,g = 0,b = 0;
  69.         if(peso < 127){
  70.                 r = Math.abs(color.getR()-peso);
  71.                 g = Math.abs(color.getG()-peso);
  72.                 b = Math.abs(color.getB()-peso);               
  73.         }
  74.         else{
  75.                 r = color.getR()+peso;
  76.                 g = color.getG()+peso;
  77.                 b = color.getB()+peso;
  78.                 if(r>max)
  79.                     r -= max;
  80.                 if(g>max)
  81.                     g -= max;
  82.                 if(b>max)
  83.                     b -= max;
  84.         }
  85.         return new Color(r,g,b);
  86.     }
  87.    
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement