myColorsv1.0

Code your own formula

Apply own formulas and ideas by extending base class of abstractFormula.

The General idea behind is, the constructor receives an array of rgb values, degree. You can calculate values of hex, hsl, hsb through pre-defined methods in the base class. After calculations convert values to hex code for red, green and blue. Finally return them connecting with concatanation.

The main class loops over the input color though formula class till it reaches limit.

Abstract Base class

Defined Methods

The abstract base class ( abstractFormula ) comes with essential fully defined methods that you can make use to calculate and convert to another mode. array rgb_to_hsl(int $red, int $green, int $blue) //returns array of hue, saturation and lightness

Abstract Method

The child class extending from abstract class must inherit the abstract method. Else it results fatal error. Here the method output() is set to abstract. And hence this method should be present in your ( formula ) class. abstract public function output();

Make use of $degree

Sometimes you need a parameter which makes the convenience of changing the calculation. And that's where the degree comes to the scene.

Naming convention and file location

File name of the class should be named as classname_formula.php. And all files should be placed in the directory '/lab/'.

Example

This example demonstrates, how to generate colors adding green element to the input color. Colors generated from this formula keeps adding $degree amount of green color to the previous colors. Hence whatever may be the input color, the generated colors would end in green. For this class the $degree value is set to 25.

save file as greeny_formula.php in '/lab/'.

	require '../core/AbstractFormula.php';

	class greeny Extends AbstractFormula
	{

		public function output()
		{
			$r = $this -> _convert($this -> _red);
			$g = $this -> _convert($this -> _green+ $this -> _degree);
			$b = $this -> _convert($this -> _blue);
			return $r . $g . $b;
		}

		private function _convert($num)
		{
			if ($num >= 256)
				return 'ff';
			elseif ($num <= 1)
				return '00';
			else
				return array_search($num, $this -> _get_hex_from_number);
		}

	}