Wlad Guz
Wlad Guz

Reputation: 75

searching harmonious colors for current color

I have a color: hex(#aeeb12) or rgb(174, 235, 18). I need to find 2 analogous colors for this color. Is there any math formulas to do it programmatically? Here is the picture:task

Upvotes: 2

Views: 323

Answers (1)

according to the site you provide in comment(sessions.edu/color-calculator) you was using analogous pattern for colors : analalogous colors make senses when you convert your rgb colors HSB/HSV representation, i redirect you to this site to understand the way this system represent colors http://colorizer.org/.

Analogous colors is a triads : leftOne mainOne rightOne In HSB representation i define the main one like this : [H, S, B]

  • H the Hue is an angle in degree
  • S the Saturation is float between 0 and 1
  • B Brightness/Value is float between 0 and 1

So leftOne if defined as : [H - 30, S, B] And rightOne if defined as : [H + 30, S, B]

In Java, if you are using the java.awt.color API,the hue is floating value (between 0 and 1) so just devide the angle by 360 ...

here is snipet from how to obtain this result in Java :

double anglerotation = 1d / 12; // 30 /360

Color mainColor = new Color(174, 235, 18);

float[] hsbLeftColor = Color.RGBtoHSB(mainColor.getRed(), mainColor.getGreen(), mainColor.getBlue(), null);
hsbLeftColor[0] -= anglerotation;
Color leftColor = new Color(Color.HSBtoRGB(hsbLeftColor[0], hsbLeftColor[1], hsbLeftColor[2]));

float[] hsbRightColor = Color.RGBtoHSB(mainColor.getRed(), mainColor.getGreen(), mainColor.getBlue(), null);
hsbRightColor[0] += anglerotation;
Color rightColor = new Color(Color.HSBtoRGB(hsbRightColor[0], hsbRightColor[1], hsbRightColor[2]));

Upvotes: 1

Related Questions