[ class tree: phpchartPlus ] [ index: phpchartPlus ] [ all elements ]

Source for file ColorAllocator.php

Documentation is available at ColorAllocator.php

  1. <?php
  2.  
  3. /*
  4. **************************************************
  5. Class: ColorAllocator.php
  6. **************************************************
  7. Author: Tsiavos Chris <jaames@freemail.gr>
  8. Date: October 2004
  9. **************************************************/
  10.  
  11. /**
  12. *Allocator for chart colors
  13. *
  14. *@author Tsiavos Chris <jaames@freemail.gr>
  15. *@license http://opensource.org/licenses/gpl-license.php GNU Public License
  16. */
  17.  
  18. class ColorAllocator {
  19.  
  20. const AliceBlue="240,248,255";
  21. const AntiqueWhite="250,235,215";
  22. const Aqua="0,255,255";
  23. const Aquamarine="127,255,212";
  24. const Azure="240,255,255";
  25. const Beige="245,245,220";
  26. const Bisque="255,228,196";
  27. const Black="0,0,0";
  28. const BlanchedAlmond="255,235,205";
  29. const Blue="0,0,255";
  30. const BlueViolet="138,43,226";
  31. const Brown="165,42,42";
  32. const BurlyWood="222,184,135";
  33. const CadetBlue="95,158,160";
  34. const Chartreuse="127,255,0";
  35. const Chocolate="210,105,30";
  36. const Coral="255,127,80";
  37. const CornflowerBlue="100,149,237";
  38. const Cornsilk="255,248,220";
  39. const Crimson="237,164,61";
  40. const Cyan="0,255,255";
  41. const DarkBlue="0,0,139";
  42. const DarkCyan="0,139,139";
  43. const DarkGoldenRod="184,134,11";
  44. const DarkGray="167,167,167";
  45. const DarkGreen="0,100,0";
  46. const DarkKhaki="189,183,107";
  47. const DarkMagenta="139,0,139";
  48. const DarkOliveGreen="85,107,47";
  49. const DarkOrange="255,140,0";
  50. const DarkOrchid="153,50,204";
  51. const DarkRed="139,0,0";
  52. const DarkSalmon="233,150,122";
  53. const DarkSeaGreen="143,188,143";
  54. const DarkSlateBlue="72,61,139";
  55. const DarkSlateGray="47,79,79";
  56. const DarkTurquoise="0,206,209";
  57. const DarkViolet="148,0,211";
  58. const DeepPink="255,20,147";
  59. const DeepSkyBlue="0,191,255";
  60. const DimGray="105,105,105";
  61. const DogderBlue="30,144,255";
  62. const Feldspar="209,146,117";
  63. const FireBrick="178,34,34";
  64. const FloralWhite="255,250,240";
  65. const ForestGreen="34,139,34";
  66. const Fuchsia="255,0,255";
  67. const Gainsboro="220,220,220";
  68. const GhostWhite="248,248,255";
  69. const Gold="255,215,0";
  70. const GoldenRod="218,165,32";
  71. const Gray="190,190,190";
  72. const Green="0,128,0";
  73. const GreenYellow="173,255,47";
  74. const HoneyDew="240,255,240";
  75. const HotPink="255,105,180";
  76. const IndianRed="205,92,92";
  77. const Indigo="75,0,130";
  78. const Ivory="255,255,240";
  79. const Khaki="240,230,140";
  80. const Lavender="230,230,250";
  81. const LavenderBlush="255,240,245";
  82. const LawnGreen="124,252,0";
  83. const LemonChiffon="255,250,205";
  84. const LightBlue="173,216,230";
  85. const LightCoral="240,128,128";
  86. const LightCyan="224,255,255";
  87. const LightGoldenRodYellow="250,250,210";
  88. const LightGrey="211,211,211";
  89. const LightGreen="144,238,144";
  90. const LightPink="255,182,193";
  91. const LightSalmon="255,160,122";
  92. const LightSeaGreen="32,178,170";
  93. const LightSkyBlue="135,206,250";
  94. const LightSlateBlue="132,112,255";
  95. const LightSlateGray="119,136,153";
  96. const LightSteelBlue="176,196,222";
  97. const LightYellow="255,255,224";
  98. const Lime="0,255,0";
  99. const LimeGreen="50,205,50";
  100. const Linen="250,240,230";
  101. const Magenta="255,0,255";
  102. const Maroon="128,0,0";
  103. const MediumAquaMarine="102,205,170";
  104. const MediumBlue="0,0,205";
  105. const MediumOrchid="186,85,211";
  106. const MediumPurple="147,112,219";
  107. const MediumSeaGreen="60,179,113";
  108. const MediumSlateBlue="123,104,238";
  109. const MediumSpringGreen="0,250,154";
  110. const MediumTurquoise="72,209,204";
  111. const MediumVioletRed="199,21,133";
  112. const MidnightBlue="25,25,112";
  113. const MintCream="245,255,250";
  114. const MistyRose="255,228,225";
  115. const Moccasin="255,228,181";
  116. const NavajoWhite="255,222,173";
  117. const Navy="0,0,128";
  118. const OldLace="253,245,230";
  119. const Olive="128,128,0";
  120. const OliveDrab="107,142,35";
  121. const Orange="255,165,0";
  122. const OrangeRed="255,69,0";
  123. const Orchid="218,112,214";
  124. const PaleGoldenRod="238,232,170";
  125. const PaleGreen="152,251,152";
  126. const PaleTurquoise="175,238,238";
  127. const PaleVioletRed="219,112,147";
  128. const PapayaWhip="255,239,213";
  129. const PeachPuff="255,218,185";
  130. const Peru="205,133,63";
  131. const Pink="255,192,203";
  132. const Plum="221,160,221";
  133. const PowderBlue="176,224,230";
  134. const Purple="128,0,128";
  135. const Red="255,0,0";
  136. const RosyBrown="188,143,143";
  137. const RoyalBlue="65,105,225";
  138. const SaddleBrown="139,69,19";
  139. const Salmon="250,128,114";
  140. const SandyBrown="244,164,96";
  141. const SeaGreen="46,139,87";
  142. const SeaShell="255,245,238";
  143. const Sienna="160,82,45";
  144. const Silver="192,192,192";
  145. const SkyBlue="135,206,235";
  146. const SlateBlue="106,90,205";
  147. const SlateGray="112,128,144";
  148. const Snow="255,250,250";
  149. const SpringGreen="0,255,127";
  150. const SteelBlue="70,130,180";
  151. const _Tan="210,180,140";
  152. const Teal="0,128,128";
  153. const Thistle="216,191,216";
  154. const Tomato="255,99,71";
  155. const Turquoise="64,224,208";
  156. const Violet="238,130,238";
  157. const VioletRed="208,32,144";
  158. const Wheat="245,222,179";
  159. const White="255,255,255";
  160. const WhiteSmoke="245,245,245";
  161. const Yellow="255,255,0";
  162. const YellowGreen="154,205,50";
  163. /**
  164. *Holds the handlers of the allocated colors. This is useful when a client requests
  165. *the allocation of a color that is already allocated. In this case no further allocation
  166. *will occur and the pre-allocated color handler will be returned
  167. *@access private
  168. *@var array
  169. */
  170. private $AllocatedColors=array();
  171. /**
  172. *Constructor
  173. */
  174. function __construct() { }
  175. /**
  176. *Allocates the requested color
  177. *@param mixed $Canvas reference to the image identifier the color will be allocated in
  178. *@param string $StartColor
  179. *@param string $FinishColor If $FinishColor is different from $StartColor then a gradient color will be allocated
  180. */
  181. public function Allocate(&$Canvas,$StartColor,$FinishColor,$Alpha,$ARange) {
  182. $StartColor_String=constant("ColorAllocator::".$StartColor);
  183. $FinishColor_String=constant("ColorAllocator::".$FinishColor);
  184. $StartColor_RGB=explode(",",$StartColor_String);
  185. $FinishColor_RGB=explode(",",$FinishColor_String);
  186. if ($StartColor_String==$FinishColor_String) {
  187. $Red=$StartColor_RGB[0];
  188. $Green=$StartColor_RGB[1];
  189. $Blue=$StartColor_RGB[2];
  190. if (array_key_exists("$Red,$Green,$Blue,$Alpha",$this->AllocatedColors))
  191. return $this->AllocatedColors["$Red,$Green,$Blue,$Alpha"];
  192. else {
  193. $this->AllocatedColors["$Red,$Green,$Blue,$Alpha"]=ImageColorAllocateAlpha($Canvas,$Red,$Green,$Blue,$Alpha);
  194. return $this->AllocatedColors["$Red,$Green,$Blue,$Alpha"];
  195. }
  196. }
  197. else {
  198. $RangeY=abs($ARange);
  199. if ($RangeY==0) $RangeY=1;
  200. $Red_Range=abs($FinishColor_RGB[0]-$StartColor_RGB[0]);
  201. $Green_Range=abs($FinishColor_RGB[1]-$StartColor_RGB[1]);
  202. $Blue_Range=abs($FinishColor_RGB[2]-$StartColor_RGB[2]);
  203. $Red_px=$Red_Range/$RangeY;
  204. $Green_px=$Green_Range/$RangeY;
  205. $Blue_px=$Blue_Range/$RangeY;
  206. $Red=$FinishColor_RGB[0];
  207. $Green=$FinishColor_RGB[1];
  208. $Blue=$FinishColor_RGB[2];
  209. $Colors=array();
  210. for ($i=0;$i<$RangeY;$i++) {
  211. if (array_key_exists("$Red,$Green,$Blue,$Alpha",$this->AllocatedColors))
  212. array_push($Colors,$this->AllocatedColors["$Red,$Green,$Blue,$Alpha"]);
  213. else
  214. {
  215. $this->AllocatedColors["$Red,$Green,$Blue,$Alpha"]=ImageColorAllocateAlpha($Canvas,round($Red),round($Green),round($Blue),$Alpha);
  216. array_push($Colors,$this->AllocatedColors["$Red,$Green,$Blue,$Alpha"]);
  217. }
  218. if($FinishColor[0]<$StartColor[0]) $Red+=$Red_px;
  219. else $Red-=$Red_px;
  220. if($FinishColor[1]<$StartColor[1]) $Green+=$Green_px;
  221. else $Green-=$Green_px;
  222. if($FinishColor[2]<$StartColor[2]) $Blue+=$Blue_px;
  223. else $Blue-=$Blue_px;
  224. }
  225. return $Colors;
  226. }
  227. }
  228. }
  229.  
  230. ?>

Documentation generated on Sun, 3 Oct 2004 14:59:03 +0300 by phpDocumentor 1.3.0RC3