1<?php
2
3require_once(dirname(__FILE__).'/Color.php');
4
5class Palette {
6	/** @todo Are the keys on this array always numbers, and always
7	 * sequential?  That's the way it's used in the code, but I don't
8	 * think we enforce that anywhere. Is enforcing it a sensible
9	 * thing to do? */
10	public $colors = array();
11
12	static public function defaultPalette() {
13		$palette = new Palette;
14
15		$palette->colors = array('0' => new Color(188, 224, 46 ),
16								 "1" => new Color(224, 100, 46 ),
17								 "2" => new Color(224, 214, 46 ),
18								 "3" => new Color(46, 151, 224 ),
19								 "4" => new Color(176, 46, 224 ),
20								 "5" => new Color(224, 46, 117 ),
21								 "6" => new Color(92, 224, 46 ),
22								 "7" => new Color(224, 176, 46 ) );
23
24		return $palette;
25	}
26
27	static public function colorGradientPalette(Color $color1, Color $color2, $shades) {
28		$palette = new Palette();
29
30		$RFactor = ($color2->getR() - $color1->getR()) / $shades;
31		$GFactor = ($color2->getG() - $color1->getG()) / $shades;
32		$BFactor = ($color2->getB() - $color1->getB()) / $shades;
33
34		for($i = 0; $i <= $shades - 1; $i ++) {
35			$palette->colors[$i] = new Color($color1->getR() + $RFactor * $i,
36											 $color1->getG() + $GFactor * $i,
37											 $color1->getB() + $BFactor * $i);
38		}
39
40		return $palette;
41	}
42
43	public function setColor($id, Color $color) {
44		$this->colors[$id] = $color;
45	}
46}