<a id="examples"></a>

# Examples

<a id="library-examples"></a>

## Library Examples

Generate a palette from HSL color space. 

```cpp
#include <qualpal.h>

qualpal::Qualpal qp;

qp.setInputColorspace({ -170, 60 }, { 0, 0.7 }, { 0.2, 0.8 });
auto hsl_pal = qp.generate(5);
```

![Five colors from the HSL color space](<../../assets/1acf4448a3d280e608f2e5a19b63beb5a1ec5389194cad5091598f779a874086.png>) 

Select colors considering color vision deficiency: 

```cpp
qp.setInputPalette("ColorBrewer:Set2").setCvd({ { "deutan", 0.7 } });
auto cvd_pal = qp.generate(4);
```

![Four colors from ColorBrewer Set2 palette with deuteranomaly simulation](<../../assets/1e2206cfebd9aaa34267139a213d177423bac1bad618b15c32e87bf430a46468.png>) 

Here we design a CVD-friendly version of the `"ColorBrewer:Set2"` palette for a black background, selecting 3 colors. 

```cpp
qp.setInputPalette("ColorBrewer:Set2")
  .setBackground(colors::RGB("#000000"))
  .setCvd({ { "tritan", 0.2 }, { "deutan", 0.5 } })
  .generate(3);
```

![Three colors from ColorBrewer Set2 palette with tritanomaly and deuteranomaly simulation on black background](<../../assets/3fa7d1aaf970986d447f1af171e44fd8040b4c3d6f5fba914363335495b3ea35.png>) 

Generate a palette from custom RGB colors: 

```cpp
qp.setInputRGB({
  colors::RGB("#e41a1c"), // Red
  colors::RGB("#377eb8"), // Blue
  colors::RGB("#4daf4a"), // Green
  colors::RGB("#984ea3"), // Purple
  colors::RGB("#ff7f00"), // Orange
});
auto rgb_pal = qp.generate(3);
```

![Three colors from given RGB input](<../../assets/8d21193e02342d9493e73e8068a050337fd01268c7b28073169dda07cfbfcc2f.png>) 

Generate a palette using a predefined palette: 

```cpp
qp.setInputPalette("Pokemon:Porygon");
auto palette = qp.generate(4);
```

![Four colors from the Pokemon Porygon palette](<../../assets/514f40cc19f0e95f1169fca513e4a6bbcbcf3d3fe1e0431ef43c9850e78456bd.png>) 

<a id="examples-cli"></a>

## Command Line Examples

Generate 5 colors from HSL color space: 

```bash
qualpal -n 5 -i colorspace "-170:60" "0:0.7" "0.2:0.8"
```

![Five colors from the HSL color space](<../../assets/1acf4448a3d280e608f2e5a19b63beb5a1ec5389194cad5091598f779a874086.png>) 

Select 2 colors from hex values: 

```bash
qualpal -n 2 "#ff0000" "#00ff00" "#0000ff"
```

![Two colors from hex RGB input](<../../assets/319d467ec71a85cfafc1176944549ffc0541cb07aadf0389a6c4b364dc6971c3.png>) 

Output palette as comma-delimited values: 

```bash
qualpal -n 4 --output-delim comma "#ff0000" "#00ff00" "#0000ff" "#ffff00"
```

```
#ff0000,#0000ff,#00ff00,#ffff00
```

Analyze a palette for color difference: 

```bash
qualpal analyze --input hex "#ff0000" "#00ff00" "#0000ff"
```

```
    Color Difference Matrix (ciede2000 metric):
    Colors analyzed: 3
    Colors:
    Idx      Hex  MinDist
        0  #ff0000    52.88
        1  #00ff00    83.19
        2  #0000ff    52.88

    Color Difference Matrix:
            0       1       2
    0     0.00   86.61   52.88
    1    86.61    0.00   83.19
    2    52.88   83.19    0.00
```

Generate palette for a dark background 

```bash
qualpal -n 2 --background "#000000" "#e41a1c" "#377eb8" "#4daf4a" "#984ea3"
```

![Two colors from given RGB input optimized for black background](<../../assets/57a6f806d89f42efb74aea191de9784b851b8557da549dbdaeecf9ec93a8d9ae.png>) 

Simulate color vision deficiency (CVD) 

```bash
qualpal -n 4 --deutan 0.7 "#e41a1c" "#377eb8" "#4daf4a" "#984ea3"
```

![Four colors from given RGB input with deuteranomaly simulation](<../../assets/02f141856b2ea2de877c4a7d4e61ac76e03cfe4c6cfdd496397b5edf69326a4f.png>) 

Improve an existing palette and select subset 

```bash
qualpal -n 3 -i palette "ColorBrewer:Set2" -b "#000000" --deutan 0.5 --tritan 0.2
```

![Three colors from ColorBrewer Set2 palette with tritanomaly and deuteranomaly simulation on black background](<../../assets/3fa7d1aaf970986d447f1af171e44fd8040b4c3d6f5fba914363335495b3ea35.png>) 

A soothing pastel palette, generated from a HSL color space: 

```bash
qualpal -n 5 -i colorspace "20:300" "0.3:0.7" "0.7:0.9"
```

![A palette of pastels](<../../assets/0596428807863b3c602e2e1fd7808ee655fdc3bb076da3542c6fcb01b41781a1.png>) 

Extend an existing palette: 

```bash
qualpal -n 4 -i hex "#4daf4a" "#984ea3" "#ff7f00" "#ffff33" --extend "#e41a1c" "#377eb8"
```

![A fixed palette of red and blue extended with four colors from given RGB input](<../../assets/62709ad03f14bd8673fcb606c852dabe72cf288dc885e8f4ff0867ff20ed2795.png>)
