Advertisement
AviEzerzer

RGBColor for EXE13

Dec 12th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. public class RGBColor
  2. {
  3.   private final int MAX_COLOR = 255;
  4.   private int _red;
  5.   private int _green;
  6.   private int _blue;
  7.  
  8.   public RGBColor()
  9.   {
  10.     this._red = 0;
  11.     this._green = 0;
  12.     this._blue = 0;
  13.   }
  14.  
  15.   public RGBColor(int red, int green, int blue)
  16.   {
  17.     if ((red > 255) || (red < 0) || (green > 255) || (green < 0) || (blue > 255) || (blue < 0))
  18.     {
  19.       this._red = 0;
  20.       this._green = 0;
  21.       this._blue = 0;
  22.     }
  23.     else
  24.     {
  25.       this._red = red;
  26.       this._green = green;
  27.       this._blue = blue;
  28.     }
  29.   }
  30.  
  31.   public RGBColor(RGBColor other)
  32.   {
  33.     this._red = other._red;
  34.     this._green = other._green;
  35.     this._blue = other._blue;
  36.   }
  37.  
  38.   public int getRed()
  39.   {
  40.     return this._red;
  41.   }
  42.  
  43.   public int getGreen()
  44.   {
  45.     return this._green;
  46.   }
  47.  
  48.   public int getBlue()
  49.   {
  50.     return this._blue;
  51.   }
  52.  
  53.   public void setRed(int red)
  54.   {
  55.     if ((red > 255) || (red < 0)) {
  56.       this._red = 0;
  57.     } else {
  58.       this._red = red;
  59.     }
  60.   }
  61.  
  62.   public void setGreen(int green)
  63.   {
  64.     if ((green > 255) || (green < 0)) {
  65.       this._green = 0;
  66.     } else {
  67.       this._green = green;
  68.     }
  69.   }
  70.  
  71.   public void setBlue(int blue)
  72.   {
  73.     if ((blue > 255) || (blue < 0)) {
  74.       this._blue = 0;
  75.     } else {
  76.       this._blue = blue;
  77.     }
  78.   }
  79.  
  80.   public void invert()
  81.   {
  82.     this._red = (255 - this._red);
  83.     this._green = (255 - this._green);
  84.     this._blue = (255 - this._blue);
  85.   }
  86.  
  87.   public void mix(RGBColor other)
  88.   {
  89.     this._red = ((other._red + this._red) / 2);
  90.     this._green = ((other._green + this._green) / 2);
  91.     this._blue = ((other._blue + this._blue) / 2);
  92.   }
  93.  
  94.   public double convertToGrayscale()
  95.   {
  96.     return this._red * 0.3D + this._green * 0.59D + this._blue * 0.11D;
  97.   }
  98.  
  99.   public boolean equals(RGBColor other)
  100.   {
  101.     return (this._red == other._red) && (this._green == other._green) && (this._blue == other._blue);
  102.   }
  103.  
  104.   public String toString()
  105.   {
  106.     return "(" + this._red + "," + this._green + "," + this._blue + ")";
  107.   }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement