c4de18b38dcb83731d30e076a8ae44ba18580ed2
[jalview.git] / src / jalview / util / ColorUtils.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 /**
19  * author: Lauren Michelle Lui
20  */
21
22 package jalview.util;
23
24 import java.awt.Color;
25 import java.util.Random;
26
27 public class ColorUtils
28 {
29
30   /**
31    * Generates a random color, will mix with input color. Code taken from
32    * http://stackoverflow
33    * .com/questions/43044/algorithm-to-randomly-generate-an-aesthetically
34    * -pleasing-color-palette
35    * 
36    * @param mix
37    * @return Random color in RGB
38    */
39   public static final Color generateRandomColor(Color mix)
40   {
41     Random random = new Random();
42     int red = random.nextInt(256);
43     int green = random.nextInt(256);
44     int blue = random.nextInt(256);
45
46     // mix the color
47     if (mix != null)
48     {
49       red = (red + mix.getRed()) / 2;
50       green = (green + mix.getGreen()) / 2;
51       blue = (blue + mix.getBlue()) / 2;
52     }
53
54     Color color = new Color(red, green, blue);
55     return color;
56
57   }
58
59 }