Skip to content

02 Assigning values

tei187 edited this page Apr 23, 2024 · 2 revisions

Typical assignment

In most cases, assigning values is just based on passing array of 3 values.

use tei187\ColorTools\ColorModels\Lab;

$lab = new Lab();
$lab->setValues([ 63.12, -3.12, 3.31 ]);

RGB

RGB is a special case, due to differences between most typically used methods for transcribing it's values, there are three ways allowed to assign values. RGB-based models can assign values in three different methods, using

  • 0 to 1 floats,
  • 0 to 255 floats
  • 00 to ff hex strings.
use tei187\ColorTools\ColorModels\RGB;

$rgb = new RGB();

$float_0_1 = $rgb->setValues([ .31, .54, .25 ])->getValues();
/*
array(3) {
  ["R"]=> float(0.31)
  ["G"]=> float(0.54)
  ["B"]=> float(0.25)
}
*/

$float_0_255 = $rgb->setValues([ 67, 123, 201 ])->getValues();
/*
array(3) {
  ["R"]=> float(0.26274509803922)
  ["G"]=> float(0.48235294117647)
  ["B"]=> float(0.78823529411765)
}
*/

$hex_00_ff = $rgb->setValues("#c5834f")->getValues();
/*
array(3) {
  ["R"]=> float(0.77254901960784)
  ["G"]=> float(0.51372549019608)
  ["B"]=> float(0.30980392156863)
}
*/