/[gzz]/gzz/gzz/util/ColorUtil.java
ViewVC logotype

Diff of /gzz/gzz/util/ColorUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by benja, Mon Aug 19 20:54:52 2002 UTC revision 1.6 by tjl, Mon Oct 14 18:15:19 2002 UTC
# Line 1  Line 1 
1  /*    /*  
2  ColorUtil.java  ColorUtil.java
3   *       *    
4   *    Copyright (c) 2001, Ted Nelson and Tuomas Lukka   *    Copyright (c) 2001-2002, Ted Nelson and Tuomas Lukka
5   *   *
6   *    You may use and distribute under the terms of either the GNU Lesser   *    You may use and distribute under the terms of either the GNU Lesser
7   *    General Public License, either version 2 of the license or,   *    General Public License, either version 2 of the license or,
# Line 59  public static final String rcsid = "$Id$ Line 59  public static final String rcsid = "$Id$
59          return res;          return res;
60      }      }
61    
62    
63      public static String colorGLString(Color c) {      public static String colorGLString(Color c) {
64          //float[] f = c.getRGBColorComponents(null);          //float[] f = c.getRGBColorComponents(null);
65          //return ""+f[0]+" "+f[1]+" "+f[2];          //return ""+f[0]+" "+f[1]+" "+f[2];
# Line 76  public static final String rcsid = "$Id$ Line 77  public static final String rcsid = "$Id$
77                          ((value & GREEN_MASK) >> 8) / 255f + " " +                          ((value & GREEN_MASK) >> 8) / 255f + " " +
78                          (value & BLUE_MASK) / 255f;                          (value & BLUE_MASK) / 255f;
79          }          }
80    
81        /** Get the average color of an array of colors.
82         */
83        public static Color avgColor(int[] colors) {
84            float r = 0, g = 0, b = 0;
85            for(int i=0; i<colors.length; i++) {
86                int c = colors[i];
87                r += (c >> 16) & 0xff;
88                g += (c >> 8) & 0xff;
89                b += (c >> 0) & 0xff;
90            }
91            r /= colors.length;
92            g /= colors.length;
93            b /= colors.length;
94            r /= 255;
95            g /= 255;
96            b /= 255;
97            return new Color(r, g, b);
98        }
99  }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26