globaltcad / swing-tree

A small DSL library for building Swing UIs
MIT License
6 stars 0 forks source link

Improve API support for the Color type #37

Closed Gleethos closed 5 months ago

Gleethos commented 6 months ago

There are a bunch of basic operations we should support for working with the Color object. For example, interpolating between colors:

    private static Color colorBetween(Color first, Color second, double percentageOfSecond) {
       double percentageOfFirst = ( 1 - percentageOfSecond );
       float[] cc = first.getComponents(null);
       float[] dd = second.getComponents(null);
       float[] result = new float[4];
       for ( int i = 0; i < 4; i++ )
           result[i] = (float) (percentageOfFirst * cc[i] + (1 - percentageOfFirst) * dd[i]);

       return new Color(result[0], result[1], result[2], result[3]);
   }