neoaikon

Android Color - a XNA styled color class for Android

Mar 24th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.63 KB | None | 0 0
  1. package com.example.android;
  2.  
  3. /* Android Color Class - An android port of the XNA Color Structure
  4.  * http://msdn.microsoft.com/en-us/library/bb195312(v=xnagamestudio.31).aspx
  5.  *
  6.  * Copyright (C) 2013  Mykel Aikon
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>
  19. */
  20.  
  21. public class Color {
  22.    
  23.     // Color members
  24.     public static Color AliceBlue =                     new Color(240, 248, 255);
  25.     public static Color AntiqueWhite =                  new Color(250, 235, 215);
  26.     public static Color Aqua =                      new Color(0, 255, 255);
  27.     public static Color AquaMarine =                    new Color(127, 255, 212);
  28.     public static Color Azure =                         new Color(240, 255, 255);
  29.     public static Color Beige =                         new Color(245, 245, 220);
  30.     public static Color Bisque =                        new Color(255, 228, 196);
  31.     public static Color Black =                         new Color(0, 0, 0);
  32.     public static Color BlanchedALmond =                    new Color(255, 235, 205);
  33.     public static Color Blue =                      new Color(0, 0, 255);
  34.     public static Color BlueViolet =                    new Color(138, 43, 226);
  35.     public static Color Brown =                         new Color(165, 42, 42);
  36.     public static Color BurlyWood =                     new Color(222, 184, 135);
  37.     public static Color CadetBlue =                     new Color(95, 158, 160);
  38.     public static Color Chartreuse =                    new Color(127, 255, 0);
  39.     public static Color Chocolate =                     new Color(210, 105, 30);
  40.     public static Color Coral =                         new Color(255, 127, 80);
  41.     public static Color CornflowerBlue =                    new Color(100, 149, 237);
  42.     public static Color Cornsilk  =                     new Color(255, 248, 220);
  43.     public static Color Crimson =                       new Color(220, 20, 60);
  44.     public static Color Cyan =                      new Color(0, 255, 255);
  45.     public static Color DarkBlue =                      new Color(0, 0, 139);
  46.     public static Color DarkCyan =                      new Color(0, 139, 139);
  47.     public static Color DarkGoldenRod =                     new Color(184, 134, 11);
  48.     public static Color DarkGray =                      new Color(169, 169, 169);
  49.     public static Color DarkGreen =                     new Color(0, 100, 0);
  50.     public static Color DarkKhaki =                     new Color(189, 183, 107);
  51.     public static Color DarkMagenta =                   new Color(139, 0, 139);
  52.     public static Color DarkOliveGreen =                    new Color(85, 107, 47);
  53.     public static Color DarkOrange =                    new Color(255, 140, 0);
  54.     public static Color DarkOrchid =                    new Color(153, 50, 204);
  55.     public static Color DarkRed =                       new Color(139, 0, 0);
  56.     public static Color DarkSalmon =                    new Color(233, 150, 122);
  57.     public static Color DarkSeaGreen =                  new Color(143, 188, 139);
  58.     public static Color DarkSlateBlue =                     new Color(72, 61, 139);
  59.     public static Color DarkSlateGray =                     new Color(47, 79, 79);
  60.     public static Color DarkTurquoise =                     new Color(0, 206, 209);
  61.     public static Color DarkViolet =                    new Color(148, 0, 211);
  62.     public static Color DeepPink =                      new Color(255, 20, 147);
  63.     public static Color DeepSkyBlue =                   new Color(0, 191, 255);
  64.     public static Color DimGray =                       new Color(105, 105, 105);
  65.     public static Color DodgerBlue =                    new Color(30, 144, 255);
  66.     public static Color Firebrick =                     new Color(178, 34, 34);
  67.     public static Color FloralWhite =                   new Color(255, 250, 240);
  68.     public static Color ForestGreen =                   new Color(34, 139, 34);
  69.     public static Color Fuchsia =                       new Color(255, 0, 255);
  70.     public static Color Gainsboro =                     new Color(220, 220, 220);
  71.     public static Color GhostWhite =                    new Color(248, 248, 255);
  72.     public static Color Gold =                      new Color(255, 215, 0);
  73.     public static Color Goldenrod =                     new Color(218, 165, 32);
  74.     public static Color Gray =                      new Color(128, 128, 128);
  75.     public static Color Green =                         new Color(0, 128, 0);
  76.     public static Color GreenYellow =                   new Color(173, 255, 47);
  77.     public static Color Honeydew =                      new Color(240, 255, 240);
  78.     public static Color HotPink =                       new Color(255, 105, 180);
  79.     public static Color IndianRed =                     new Color(205, 92, 92);
  80.     public static Color Indigo =                        new Color(75, 0, 130);
  81.     public static Color Ivory =                         new Color(255, 255, 240);
  82.     public static Color Khaki =                         new Color(240, 230, 140);
  83.     public static Color Lavender =                      new Color(230, 230, 250);
  84.     public static Color LavenderBlush =                     new Color(255, 240, 245);
  85.     public static Color LawnGreen =                     new Color(124, 252, 0);
  86.     public static Color LemonChiffon =                  new Color(255, 250, 205);
  87.     public static Color LightBlue =                     new Color(173, 216, 230);
  88.     public static Color LightCoral =                    new Color(240, 128, 128);
  89.     public static Color LightCyan =                     new Color(224, 255, 255);
  90.     public static Color LightGoldenrodYellow =              new Color(250, 250, 210);
  91.     public static Color LightGray =                     new Color(211, 211, 211);
  92.     public static Color LightGreen =                    new Color(144, 238, 144);
  93.     public static Color LightPink =                     new Color(255, 182, 193);
  94.     public static Color LightSalmon =                   new Color(255, 160, 122);
  95.     public static Color LightSeaGreen =                     new Color(32, 178, 170);
  96.     public static Color LightSkyBlue =                  new Color(135, 206, 250);
  97.     public static Color LightSlateGray =                    new Color(119, 136, 153);
  98.     public static Color LightSteelBlue =                    new Color(176, 196, 222);
  99.     public static Color LightYellow =                   new Color(255, 255, 224);
  100.     public static Color Lime =                      new Color(0, 255, 0);
  101.     public static Color LimeGreen =                     new Color(50, 205, 50);
  102.     public static Color Linen =                         new Color(250, 240, 230);
  103.     public static Color Magenta =                       new Color(255, 0, 255);
  104.     public static Color Maroon =                        new Color(128, 0, 0);
  105.     public static Color MediumAquamarine =                  new Color(102, 205, 170);
  106.     public static Color MediumBlue =                    new Color(0, 0, 205);
  107.     public static Color MediumOrchid =                  new Color(186, 85, 211);
  108.     public static Color MediumPurple =                  new Color(147, 112, 219);
  109.     public static Color MediumSeaGreen =                    new Color(60, 179, 113);
  110.     public static Color MediumSlateBlue =                   new Color(123, 104, 238);
  111.     public static Color MediumSpringGreen =                 new Color(0, 250, 154);
  112.     public static Color MediumTurquoise =                   new Color(72, 209, 204);
  113.     public static Color MediumVioletRed =                   new Color(199, 21, 133);
  114.     public static Color MidnightBlue =                  new Color(25, 25, 112);
  115.     public static Color MintCream =                     new Color(245, 255, 250);
  116.     public static Color MistyRose =                     new Color(255, 228, 225);
  117.     public static Color Moccasin =                      new Color(255, 228, 181);
  118.     public static Color NavajoWhite =                   new Color(255, 222, 173);
  119.     public static Color Navy =                      new Color(0, 0, 128);
  120.     public static Color OldLace =                       new Color(253, 245, 230);
  121.     public static Color Olive =                         new Color(128, 128, 0);
  122.     public static Color OliveDrab =                     new Color(107, 142, 35);
  123.     public static Color Orange =                        new Color(255, 165, 0);
  124.     public static Color OrangeRed =                     new Color(255, 69, 0);
  125.     public static Color Orchid =                        new Color(218, 112, 214);
  126.     public static Color PaleGoldenrod =                     new Color(238, 232, 170);
  127.     public static Color PaleGreen =                     new Color(152, 251, 152);
  128.     public static Color PaleTurquoise =                     new Color(175, 238, 238);
  129.     public static Color PaleVioletRed =                     new Color(219, 112, 147);
  130.     public static Color PapayaWhip =                    new Color(255, 239, 213);
  131.     public static Color PeachPuff =                     new Color(255, 218, 185);
  132.     public static Color Peru =                      new Color(205, 133, 63);
  133.     public static Color Pink =                      new Color(255, 192, 203);
  134.     public static Color Plum =                      new Color(221, 160, 221);
  135.     public static Color PowderBlue =                    new Color(176, 224, 230);
  136.     public static Color Purple =                        new Color(128, 0, 128);
  137.     public static Color Red =                       new Color(255, 0, 0);
  138.     public static Color RosyBrown =                     new Color(188, 143, 143);
  139.     public static Color RoyalBlue =                     new Color(65, 105, 225);
  140.     public static Color SaddleBrown =                   new Color(139, 69, 19);
  141.     public static Color Salmon =                        new Color(250, 128, 114);
  142.     public static Color SandyBrown =                    new Color(244, 164, 96);
  143.     public static Color SeaGreen =                      new Color(46, 139, 87);
  144.     public static Color SeaShell =                      new Color(255, 245, 238);
  145.     public static Color Sienna =                        new Color(160, 82, 45);
  146.     public static Color Silver =                        new Color(192, 192, 192);
  147.     public static Color SkyBlue =                       new Color(135, 206, 235);
  148.     public static Color SlateBlue =                     new Color(106, 90, 205);
  149.     public static Color SlateGray =                     new Color(112, 128, 144);
  150.     public static Color Snow =                      new Color(255, 250, 250);
  151.     public static Color SpringGreen =                   new Color(0, 255, 1270);
  152.     public static Color SteelBlue =                     new Color(70, 130, 180);
  153.     public static Color Tan =                       new Color(210, 180, 140);
  154.     public static Color Teal =                      new Color(0, 128, 128);
  155.     public static Color Thistle =                       new Color(216, 191, 216);
  156.     public static Color Tomato =                        new Color(255, 99, 71);
  157.     public static Color TransparentBlack =                  new Color(0, 0, 0, 0);
  158.     public static Color TransparentWhite =                  new Color(255, 255, 255, 0);
  159.     public static Color Turquoise =                     new Color(64, 224, 208);
  160.     public static Color Violet =                        new Color(238, 130, 238);
  161.     public static Color Wheat =                         new Color(245, 222, 179);
  162.     public static Color White =                         new Color(255, 255, 255);
  163.     public static Color WhiteSmoke =                    new Color(245, 245, 245);
  164.     public static Color Yellow =                        new Color(255, 255, 0);
  165.     public static Color YellowGreen =                   new Color(154, 205, 50);
  166.    
  167.     public float R, G, B, A;
  168.    
  169.     // Constructors
  170.     public Color(int RGB) {
  171.         this.R = RGB > 255? 1.0f: (float)RGB/255.0f;
  172.         this.G = RGB > 255? 1.0f: (float)RGB/255.0f;
  173.         this.B = RGB > 255? 1.0f: (float)RGB/255.0f;
  174.         this.A = 1.0f;
  175.     }
  176.    
  177.     public Color(int RGB, int A) {
  178.         this.R = RGB > 255? 1.0f: (float)RGB/255.0f;
  179.         this.G = RGB > 255? 1.0f: (float)RGB/255.0f;
  180.         this.B = RGB > 255? 1.0f: (float)RGB/255.0f;
  181.         this.A = A > 255? 1.0f: (float)A/255.0f;
  182.     }
  183.    
  184.     public Color(float RGB) {
  185.         this.R = RGB > 1.0f? 1.0f: RGB;
  186.         this.G = RGB > 1.0f? 1.0f: RGB;
  187.         this.B = RGB > 1.0f? 1.0f: RGB;
  188.         this.A = 1.0f;
  189.     }
  190.    
  191.     public Color(float RGB, float A) {
  192.         this.R = RGB > 1.0f? 1.0f: RGB;
  193.         this.G = RGB > 1.0f? 1.0f: RGB;
  194.         this.B = RGB > 1.0f? 1.0f: RGB;
  195.         this.A = A > 1.0f? 1.0f: A;
  196.     }
  197.    
  198.     public Color(int R, int G, int B) {
  199.         this.R = R > 255? 1.0f: (float)R/255.0f;
  200.         this.G = G > 255? 1.0f: (float)G/255.0f;
  201.         this.B = B > 255? 1.0f: (float)B/255.0f;
  202.         this.A = 1.0f;
  203.     }
  204.    
  205.     public Color(int R, int G, int B, int A) {
  206.         this.R = R > 255? 1.0f: (float)R/255.0f;
  207.         this.G = G > 255? 1.0f: (float)G/255.0f;
  208.         this.B = B > 255? 1.0f: (float)B/255.0f;
  209.         this.A = A > 255? 1.0f: (float)A/255.0f;
  210.     }
  211.    
  212.     public Color(float R, float G, float B) {
  213.         this.R = R > 1.0f? 1.0f: R;
  214.         this.G = G > 1.0f? 1.0f: G;
  215.         this.B = B > 1.0f? 1.0f: B;
  216.         this.A = 1.0f;
  217.     }
  218.    
  219.     public Color(float R, float G, float B, float A) {
  220.         this.R = R > 1.0f? 1.0f: R;
  221.         this.G = G > 1.0f? 1.0f: G;
  222.         this.B = B > 1.0f? 1.0f: B;
  223.         this.A = A > 1.0f? 1.0f: A;
  224.     }
  225.    
  226.     // Returns an int representing the ARGB value  
  227.     public int getPackedValue() {
  228.         return (((short)(A * 255.0f) & 0xFF) << 24) +
  229.                 (((short)(R * 255.0f) & 0xFF) << 16) +
  230.                 (((short)(G * 255.0f) & 0xFF) << 8) +
  231.                 ((short)(B * 255.0f) & 0xFF);
  232.     }
  233. }
Advertisement
Add Comment
Please, Sign In to add comment