How to create a lighter color in Matlab?

I have a base color represented by a base matrix [RGB].

And I want to create a lighter or darker version of this color based on my constant, which is basically an angle (0 - 90 °).

And I'm looking for an algorithm on how to create a lighter or darker color based on this angle.

The end point for a lighter color is white, and for a darker color is black.

stupid example:

Green -> Lime -> White

Blue -> Navy -> Black

function [result] = GetColor(baseColor, angleValue)

    value = round(angleValue);

    endcolor = [1 1 1];

    r = linspace(basecolor(1,1), endcolor(1,1), 90);
    g = linspace(basecolor(1,2), endcolor(1,2), 90);
    b = linspace(basecolor(1,3), endcolor(1,3), 90);

    result = [r(value) g(value) b(value)];

end
+3
source share
2 answers

What is the lightest or darkest color you need? Define the end points [r1 g1 b1], [r2 g2 b2]which will correspond to 0 and 90. Then use:

colormap = [linspace(r1, r2, 91)' linspace(g1, g2, 91)' linspace(b1, b2, 91)']

91 , .

+4

Java , :

jColor = java.awt.Color(0.12,0.34,0.67);  % R,G,B fractions of 255 = [31,87,171]
lightColor = jColor.brighter.getRGBComponents([])'*255;  % => [44,124,244,255]  (4th component is alpha transparency)
darkColor = jColor.darker.getRGBComponents([])'*255;  % => [21,60,119,255]

Java /, Matlab, .

+1

Source: https://habr.com/ru/post/1779059/


All Articles