Location: PHPKode > scripts > myColors > vylson-silwr-myColors-2550f71/lab/spread_formula.php
<?php

	/**
	 * myColors
	 *
	 *	 Discover Your Colors!
	 *
	 * @author vylson silwr  <hide@address.com>
	 * @version 1.0
	 * @copyright   (C)2007 vylson silwr- GNU GPL
	 * @license       http://www.gnu.org/licenses/gpl.html GNU General public License
	 * @package myColors
	 */

	// -----------------spread_formula.php-------------------- //

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

	/**
	 * spread formula
	 *
	 *increases/ decreases lightness regularly. fetch the saturation of given color
	 * and sets to predefined value. then adds
	 * hue.
	 *
	 */

	class spread  Extends AbstractFormula
	{

		/**
		 * manipulates
		 *
		 * @return string
		 */

		public function output()
		{

			$hsl = $this -> _convert -> rgb_to_hsl(array(
				$this -> _red,
				$this -> _green,
				$this -> _blue
			));
			// finding hsl values from rgb values

			$this -> _hue = $hsl['hue'];
			// hue ranges from 0-360 degree

			$this -> _saturation = $hsl['saturation'];
			//more the saturation more the gray color

			$this -> _lightness = $hsl['lightness'];
			//increasing lightness results in raise of whiteness

			/**
			 * if lightness increased to 0.9 reduce by 0.1. else increase by 0.1
			 */
			if ($this -> _lightness >= 0.9)
				$this -> _lightness = $this -> _lightness - 0.1;
			else
				$this -> _lightness = $this -> _lightness + 0.1;

			/*
			 *hue is randomly selected
			 */
			$rand = mt_rand(1, 60);
			$divide = $rand / 100;
			$this -> _hue = $divide;

			/*
			 *saturation is set to 0.6 if 0
			 */

			if ($this -> _saturation == 0)
				$this -> _saturation = 0.60;

			/*
			 *after changing the hsl values again convert to rgb values  and return as hex by
			 * finding the hex from rgb values.
			 */

			$rgb = $this -> _convert -> hsl_to_rgb($this -> _hue, $this -> _saturation, $this -> _lightness);

			$hex = $this -> _convert -> rgb_to_hex($rgb[0], $rgb[1], $rgb[2]);

			return $hex;
		}

	}

	//--------------class ends---------------//
?>
Return current item: myColors