X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FColorUtils.java;h=31d1dedad331641c63e5da78df030bd8321c57d0;hb=37de9310bec3501cbc6381e0c3dcb282fcaad812;hp=4e3d4d4d50f4bab154d7715ed293c83e9da325c8;hpb=25aaaa87042b3f507ad4348120df7dd073182759;p=jalview.git diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java index 4e3d4d4..31d1ded 100644 --- a/src/jalview/util/ColorUtils.java +++ b/src/jalview/util/ColorUtils.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -103,4 +103,43 @@ public class ColorUtils return col == null ? null : col.brighter().brighter().brighter(); } + /** + * Returns a color between minColour and maxColour; the RGB values are in + * proportion to where 'value' lies between minValue and maxValue + * + * @param value + * @param minValue + * @param minColour + * @param maxValue + * @param maxColour + * @return + */ + public static Color getGraduatedColour(float value, float minValue, + Color minColour, float maxValue, Color maxColour) + { + if (minValue == maxValue) + { + return minColour; + } + if (value < minValue) + { + value = minValue; + } + if (value > maxValue) + { + value = maxValue; + } + + /* + * prop = proportion of the way value is from minValue to maxValue + */ + float prop = (value - minValue) / (maxValue - minValue); + float r = minColour.getRed() + prop + * (maxColour.getRed() - minColour.getRed()); + float g = minColour.getGreen() + prop + * (maxColour.getGreen() - minColour.getGreen()); + float b = minColour.getBlue() + prop + * (maxColour.getBlue() - minColour.getBlue()); + return new Color(r / 255, g / 255, b / 255); + } }