Color Schemes

Color Palette PHP provides comprehensive support for generating harmonious color schemes based on color theory principles.

Overview

The color scheme functionality is primarily provided through the PaletteGenerator class:

namespace Farzai\ColorPalette;

class PaletteGenerator
{
    public function __construct(ColorInterface $baseColor)
    {
        // ...
    }
}

Color Harmony Methods

analogous

public function analogous(): ColorPalette
Generates an analogous color scheme using colors adjacent on the color wheel.

Returns

ColorPalette with three colors: base color and two adjacent colors (±30°)

complementary

public function complementary(): ColorPalette
Creates a complementary color scheme using opposite colors on the color wheel.

Returns

ColorPalette with two colors: base color and its complement (180°)

triadic

public function triadic(): ColorPalette
Generates a triadic color scheme using three evenly spaced colors.

Returns

ColorPalette with three colors spaced 120° apart

tetradic

public function tetradic(): ColorPalette
Creates a tetradic (double complementary) color scheme.

Returns

ColorPalette with four colors forming a rectangle on the color wheel

splitComplementary

public function splitComplementary(): ColorPalette
Generates a split-complementary color scheme.

Returns

ColorPalette with three colors: base and two colors adjacent to its complement

Monochromatic Variations

monochromatic

public function monochromatic(int $count = 5): ColorPalette
Creates variations of the base color with different lightness values.

Parameters

Name Type Description
$count int Number of variations to generate

shades

public function shades(int $count = 5): ColorPalette
Generates darker variations of the base color.

Parameters

Name Type Description
$count int Number of shades to generate

tints

public function tints(int $count = 5): ColorPalette
Creates lighter variations of the base color.

Parameters

Name Type Description
$count int Number of tints to generate

Theme Generation

websiteTheme

public function websiteTheme(): ColorPalette
Generates a complete website color theme based on the base color.

Returns

ColorPalette containing:

  • primary: Base color
  • secondary: Desaturated complementary
  • accent: Saturated complementary
  • background: Light neutral
  • surface: White or near-white

Examples

Basic Color Schemes

use Farzai\ColorPalette\Color;
use Farzai\ColorPalette\PaletteGenerator;

// Create a base color
$baseColor = new Color(37, 99, 235); // Blue
$generator = new PaletteGenerator($baseColor);

// Generate different schemes
$analogous = $generator->analogous();
$complementary = $generator->complementary();
$triadic = $generator->triadic();
$tetradic = $generator->tetradic();
$splitComp = $generator->splitComplementary();

Monochromatic Variations

// Generate variations
$mono = $generator->monochromatic(5);
$shades = $generator->shades(5);
$tints = $generator->tints(5);

// Access variations
foreach ($mono->getColors() as $color) {
    echo $color->toHex() . "\n";
}

Website Theme Generation

// Generate website theme
$theme = $generator->websiteTheme();

// Access theme colors
$primary = $theme->getColors()['primary'];
$secondary = $theme->getColors()['secondary'];
$accent = $theme->getColors()['accent'];
$background = $theme->getColors()['background'];
$surface = $theme->getColors()['surface'];

Color Theory Guide

Analogous Colors

Complementary Colors

Triadic Colors

Split-Complementary

Tetradic (Double Complementary)

Best Practices

  1. Color Harmony
    • Start with a meaningful base color
    • Use complementary colors for emphasis
    • Use analogous colors for harmony
    • Consider color psychology
  2. Accessibility
    • Ensure sufficient contrast ratios
    • Test color combinations for color blindness
    • Provide alternative visual cues
  3. Implementation
    • Cache generated color schemes
    • Validate color combinations
    • Consider context and purpose

See Also