From: gmungoc Date: Fri, 4 May 2018 14:34:09 +0000 (+0100) Subject: JAL-2965 graduate brightness on z-axis from centre of display X-Git-Tag: Release_2_11_1_0~78^2~9^2~7 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b6b044f8887234eb5ee0146064b906f5ca2a74a5;p=jalview.git JAL-2965 graduate brightness on z-axis from centre of display --- diff --git a/src/jalview/gui/RotatableCanvas.java b/src/jalview/gui/RotatableCanvas.java index 2053f94..da48dd6 100755 --- a/src/jalview/gui/RotatableCanvas.java +++ b/src/jalview/gui/RotatableCanvas.java @@ -27,6 +27,7 @@ import jalview.datamodel.SequenceI; import jalview.datamodel.SequencePoint; import jalview.math.RotatableMatrix; import jalview.math.RotatableMatrix.Axis; +import jalview.util.ColorUtils; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; @@ -436,9 +437,20 @@ public class RotatableCanvas extends JPanel implements MouseListener, sequenceColour = Color.gray; } } - if (sp.coord.z < 0f) + + /* + * graduate brighter for point in front of centre, darker if behind centre + */ + float zCentre = (seqMin[2] + seqMax[2]) / 2f; + if (sp.coord.z > zCentre) + { + sequenceColour = ColorUtils.getGraduatedColour(sp.coord.z, 0, + sequenceColour, seqMax[2], sequenceColour.brighter()); + } + else if (sp.coord.z < zCentre) { - sequenceColour = sequenceColour.darker(); + sequenceColour = ColorUtils.getGraduatedColour(sp.coord.z, seqMin[2], + sequenceColour.darker(), 0, sequenceColour); } return sequenceColour; diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java index 16ff259..60129fb 100644 --- a/src/jalview/util/ColorUtils.java +++ b/src/jalview/util/ColorUtils.java @@ -31,9 +31,6 @@ import java.util.Random; public class ColorUtils { - // constant borrowed from java.awt.Color - private static final float FACTOR = 0.7f; - private static final int MAX_CACHE_SIZE = 1729; /* * a cache for colours generated from text strings @@ -375,63 +372,4 @@ public class ColorUtils return col; } - - /** - * Generates a colour that is interpolated between - * colour.darker() and colour.brighter() in - * proportion as value is between min and - * max. Note that the 'neutral point' (unchanged colour) is - * closer to 'brighter' than to 'darker'as this is a geometric range. - * - * @param value - * @param min - * @param max - * @param colour - * @return - */ - public static Color getGraduatedColour(float value, float min, float max, - Color colour) - { - /* - * this computes the equivalent of - * getGraduatedColour(value, min, colour.darker(), max, colour.brighter()) - * but avoiding object creation except for the return value - */ - if (value < min) - { - value = min; - } - if (value > max) - { - value = max; - } - - int r = colour.getRed(); - int g = colour.getGreen(); - int b = colour.getBlue(); - - /* - * rgb for colour.darker(): - */ - float minR = r * FACTOR; - float minG = g * FACTOR; - float minB = b * FACTOR; - - /* - * rgb for colour.brighter(): - */ - float maxR = Math.min(255f, r / FACTOR); - float maxG = Math.min(255f, g / FACTOR); - float maxB = Math.min(255f, b / FACTOR); - - /* - * interpolation - */ - float p = (value - min) / (max - min); - int newR = (int) (minR + p * (maxR - minR)); - int newG = (int) (minG + p * (maxG - minG)); - int newB = (int) (minB + p * (maxB - minB)); - - return new Color(newR, newG, newB, colour.getAlpha()); - } } diff --git a/test/jalview/util/ColorUtilsTest.java b/test/jalview/util/ColorUtilsTest.java index 0acd806..fa4091f 100644 --- a/test/jalview/util/ColorUtilsTest.java +++ b/test/jalview/util/ColorUtilsTest.java @@ -243,48 +243,4 @@ public class ColorUtilsTest assertEquals(new Color(184, 184, 184), ColorUtils.createColourFromName("HELLO HELLO HELLO ")); } - - /** - * Tests for the method that returns a colour graduated between darker() and - * brighter() - */ - @Test(groups = { "Functional" }) - public void testGetGraduatedColour_darkerToBrighter() - { - final Color colour = new Color(180, 200, 220); - - /* - * value half-way between min and max does _not_ mean colour unchanged - * darker (*.7) is (126, 140, 154) - * brighter (*1/.7) is (255, 255, 255) - * midway is (190, 197, 204) - */ - Color col = ColorUtils.getGraduatedColour(20f, 10f, 30f, colour); - assertEquals(190, col.getRed()); - assertEquals(197, col.getGreen()); - assertEquals(204, col.getBlue()); - - // minValue (or less) returns colour.darker() - // - or would do if Color.darker calculated better! - col = ColorUtils.getGraduatedColour(10f, 10f, 30f, colour); - assertEquals(col, new Color(126, 140, 154)); - // Color.darker computes 125.999999 and rounds down! - assertEquals(new Color(125, 140, 154), colour.darker()); - col = ColorUtils.getGraduatedColour(-10f, 10f, 30f, colour); - assertEquals(new Color(126, 140, 154), col); - - // maxValue (or more) returns colour.brighter() - col = ColorUtils.getGraduatedColour(30f, 10f, 30f, colour); - assertEquals(colour.brighter(), col); - col = ColorUtils.getGraduatedColour(40f, 10f, 30f, colour); - assertEquals(colour.brighter(), col); - - /* - * 'linear' mid-point between 0.7 and 1/0.7 is 1.057 - * so the ' - */ - Color c = new Color(200, 200, 200); - col = ColorUtils.getGraduatedColour(106f, 0f, 200f, c); - assertEquals(c, col); - } }