Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import aguiaj.iscte.*;
- public class Parte1 {
- //Questao 1
- public static ColorImage copy(ColorImage img){
- ColorImage newImage = new ColorImage (img.getWidth(), img.getHeight());
- for(int i = 0; i < img.getWidth(); i++){
- for(int j = 0; j < img.getHeight(); j++){
- newImage.setColor(i, j, img.getColor(i,j));
- }
- }
- return newImage;
- }
- public static ColorImage copyWithMargin(ColorImage img, int margin){
- ColorImage newImage = new ColorImage (img.getWidth(), img.getHeight());
- newImage = copy(img);
- Color white = new Color (255,255,255);
- for(int i = 0; i < newImage.getWidth(); i++){
- for(int j= 0; j < margin; j++){
- newImage.setColor(i, j, white);
- newImage.setColor(i, newImage.getHeight()-margin+j, white);
- }
- }
- for(int i = 0; i < margin; i++){
- for(int j= 0; j < newImage.getHeight(); j++){
- newImage.setColor(i, j, white);
- newImage.setColor(newImage.getWidth()-margin+i,j, white);
- }
- }
- return newImage;
- }
- //Questao 2
- public static BinaryImage matrix (boolean [][] mat){
- BinaryImage bin = new BinaryImage(mat.length, mat[0].length);
- for(int i = 0; i < mat.length; i++){
- for(int j = 0; j < mat[0].length; j++){
- if(mat[i][j] == true)
- bin.setBlack(i, j);
- else
- bin.setWhite(i, j);
- }
- }
- return bin;
- }
- //Cria uma matriz random para testar com o aguiaj
- public static boolean [][] ma(int x){
- boolean [][] mat = new boolean [x][x];
- Random r = new Random();
- for(int i = 0; i < x; i++){
- for(int j=0; j < x; j++){
- mat[i][j] = r.nextBoolean();
- }
- }
- return mat;
- }
- //Questão 3
- public static Color newColor(Color color, int peso){
- int max = 255;
- int r = 0,g = 0,b = 0;
- if(peso < 127){
- r = Math.abs(color.getR()-peso);
- g = Math.abs(color.getG()-peso);
- b = Math.abs(color.getB()-peso);
- }
- else{
- r = color.getR()+peso;
- g = color.getG()+peso;
- b = color.getB()+peso;
- if(r>max)
- r -= max;
- if(g>max)
- g -= max;
- if(b>max)
- b -= max;
- }
- return new Color(r,g,b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement