Class: Color::Palette::MonoContrast

Class | Color::Palette::MonoContrast
In: | lib/color/palette/monocontrast.rb
Parent: | Object

Generates a monochromatic constrasting colour palette for background and foreground. What does this mean?

Monochromatic: A single colour is used to generate the base palette, and this colour is lightened five times and darkened five times to provide eleven distinct colours.

Contrasting: The foreground is also generated as a monochromatic colour palette; however, all generated colours are tested to see that they are appropriately contrasting to ensure maximum readability of the foreground against the background.

### Methods

brightness_diff calculate_foreground color_diff minimum_color_diff= new regenerate

### Constants

DEFAULT_MINIMUM_BRIGHTNESS_DIFF | = | (125.0 / 255.0)
DEFAULT_MINIMUM_COLOR_DIFF | = | (500.0 / 255.0)

### Attributes

background | [R] | Hash of CSS background colour values. This is always 11 values:
0: | The starting colour.
+1..+5: | Lighter colours.
-1..-5: | Darker colours.
foreground | [R] | Hash of CSS foreground colour values. This is always 11 values:
0: | The starting colour.
+1..+5: | Lighter colours.
-1..-5: | Darker colours.
minimum_brightness_diff | [RW] | The minimum brightness difference between the background and the foreground, and must be between 0..1. Setting this value will regenerate the palette based on the base colours. The default value for this is 125 / 255.0. If this value is set to `nil`, it will be restored to the default.
minimum_color_diff | [RW] | The minimum colour difference between the background and the foreground, and must be between 0..3. Setting this value will regenerate the palette based on the base colours. The default value for this is 500 / 255.0.

### Public Class methods

new(background, foreground = nil)

Generate the initial palette.

### Public Instance methods

brightness_diff(c1, c2)

Returns the absolute difference between the brightness levels of two colours. This will be a decimal value between 0 and 1. W3C accessibility guidelines for colour contrast suggest that this value be at least approximately 0.49 (125 / 255.0) for proper contrast.

calculate_foreground(background, foreground)

Given a background colour and a foreground colour, modifies the foreground colour so that it will have enough contrast to be seen against the background colour.

Uses mininum_brightness_diff and minimum_color_diff.

color_diff(c1, c2)

Returns the contrast between to colours, a decimal value between 0 and

1. W3C accessibility guidelines for colour

contrast suggest that this value be at least approximately 1.96 (500 / 255.0) for proper contrast.

minimum_color_diff=(cd)
regenerate(background, foreground = nil)

Generate the colour palettes.

[Validate]