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
- Uses colors adjacent to each other on the color wheel
- Creates harmonious and serene color combinations
- Best for creating a unified look
Complementary Colors
- Uses colors opposite each other on the color wheel
- Creates high contrast and vibrant combinations
- Best for creating emphasis and attention
Triadic Colors
- Uses three colors equally spaced on the color wheel
- Creates balanced and vibrant combinations
- Best for creating dynamic and energetic designs
Split-Complementary
- Uses a base color and two colors adjacent to its complement
- Creates high contrast but with less tension than complementary
- Best for beginners in color theory
Tetradic (Double Complementary)
- Uses four colors arranged into two complementary pairs
- Creates rich and complex color schemes
- Best for creating sophisticated designs
Best Practices
- Color Harmony
- Start with a meaningful base color
- Use complementary colors for emphasis
- Use analogous colors for harmony
- Consider color psychology
- Accessibility
- Ensure sufficient contrast ratios
- Test color combinations for color blindness
- Provide alternative visual cues
- Implementation
- Cache generated color schemes
- Validate color combinations
- Consider context and purpose