[ Index ]
 

Code source de Cr@wltr@ck 2.2.1

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/graphs/artichow/php5/inc/ -> Color.class.php (source)

   1  <?php
   2  /*
   3   * This work is hereby released into the Public Domain.
   4   * To view a copy of the public domain dedication,
   5   * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
   6   * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
   7   *
   8   */
   9   
  10  require_once dirname(__FILE__)."/../Graph.class.php";
  11  
  12  /**
  13   * Create your colors
  14   *
  15   * @package Artichow
  16   */
  17  class awColor {
  18      
  19      public $red;
  20      public $green;
  21      public $blue;
  22      public $alpha;
  23      
  24      private $resource;
  25      private $color;
  26  
  27      /**
  28       * Build your color
  29       *
  30       * @var int $red Red intensity (from 0 to 255)
  31       * @var int $green Green intensity (from 0 to 255)
  32       * @var int $blue Blue intensity (from 0 to 255)
  33       * @var int $alpha Alpha channel (from 0 to 100)
  34       */
  35  	public function __construct($red, $green, $blue, $alpha = 0) {
  36      
  37          $this->red = (int)$red;
  38          $this->green = (int)$green;
  39          $this->blue = (int)$blue;
  40          $this->alpha = (int)round($alpha * 127 / 100);
  41          
  42      }
  43      
  44      /**
  45       * Return a GDised color
  46       *
  47       * @param resource $resource A GD resource
  48       * @return int
  49       */
  50  	public function getColor($resource) {
  51      
  52          $this->resource = $resource;
  53          
  54          if($this->color === NULL) {
  55      
  56              if($this->alpha === 0 or function_exists('imagecolorallocatealpha') === FALSE) {
  57                  $this->color = imagecolorallocate($this->resource, $this->red, $this->green, $this->blue);
  58              } else {
  59                  $this->color = imagecolorallocatealpha($this->resource, $this->red, $this->green, $this->blue, $this->alpha);
  60              }
  61              
  62          }
  63          
  64          return $this->color;
  65      
  66      }
  67      
  68      /**
  69       * Change color brightness
  70       *
  71       * @param int $brightness Add this intensity to the color (betweeen -255 and +255)
  72       */
  73  	public function brightness($brightness) {
  74      
  75          $brightness = (int)$brightness;
  76      
  77          $this->red = min(255, max(0, $this->red + $brightness));
  78          $this->green = min(255, max(0, $this->green + $brightness));
  79          $this->blue = min(255, max(0, $this->blue + $brightness));
  80      
  81      }
  82      
  83      /**
  84       * Get RGB and alpha values of your color
  85       *
  86       * @return array
  87       */
  88  	public function rgba() {
  89      
  90          return array($this->red, $this->green, $this->blue, $this->alpha);
  91      
  92      }
  93      
  94      /**
  95       * Free resources used for this color
  96       */
  97  	public function free() {
  98      
  99          if($this->resource !== NULL) {
 100      
 101              @imagecolordeallocate($this->resource, $this->color);
 102              $this->resource = NULL;
 103              
 104          }
 105      
 106      }
 107      
 108  	public function __destruct() {
 109      
 110          $this->free();
 111      
 112      }
 113  
 114  }
 115  
 116  registerClass('Color');
 117  
 118  $colors = array(
 119      'Black' => array(0, 0, 0),
 120      'AlmostBlack' => array(48, 48, 48),
 121      'VeryDarkGray' => array(88, 88, 88),
 122      'DarkGray' => array(128, 128, 128),
 123      'MidGray' => array(160, 160, 160),
 124      'LightGray' => array(195, 195, 195),
 125      'VeryLightGray' => array(220, 220, 220),
 126      'White' => array(255, 255, 255),
 127      'VeryDarkRed' => array(64, 0, 0),
 128      'DarkRed' => array(128, 0, 0),
 129      'MidRed' => array(192, 0, 0),
 130      'Red' => array(255, 0, 0),
 131      'LightRed' => array(255, 192, 192),
 132      'VeryDarkGreen' => array(0, 64, 0),
 133      'DarkGreen' => array(0, 128, 0),
 134      'MidGreen' => array(0, 192, 0),
 135      'Green' => array(0, 255, 0),
 136      'LightGreen' => array(192, 255, 192),
 137      'VeryDarkBlue' => array(0, 0, 64),
 138      'DarkBlue' => array(0, 0, 128),
 139      'MidBlue' => array(0, 0, 192),
 140      'Blue' => array(0, 0, 255),
 141      'LightBlue' => array(192, 192, 255),
 142      'VeryDarkYellow' => array(64, 64, 0),
 143      'DarkYellow' => array(128, 128, 0),
 144      'MidYellow' => array(192, 192, 0),
 145      'Yellow' => array(255, 255, 2),
 146      'LightYellow' => array(255, 255, 192),
 147      'VeryDarkCyan' => array(0, 64, 64),
 148      'DarkCyan' => array(0, 128, 128),
 149      'MidCyan' => array(0, 192, 192),
 150      'Cyan' => array(0, 255, 255),
 151      'LightCyan' => array(192, 255, 255),
 152      'VeryDarkMagenta' => array(64, 0, 64),
 153      'DarkMagenta' => array(128, 0, 128),
 154      'MidMagenta' => array(192, 0, 192),
 155      'Magenta' => array(255, 0, 255),
 156      'LightMagenta' => array(255, 192, 255),
 157      'DarkOrange' => array(192, 88, 0),
 158      'Orange' => array(255, 128, 0),
 159      'LightOrange' => array(255, 168, 88),
 160      'VeryLightOrange' => array(255, 220, 168),
 161      'DarkPink' => array(192, 0, 88),
 162      'Pink' => array(255, 0, 128),
 163      'LightPink' => array(255, 88, 168),
 164      'VeryLightPink' => array(255, 168, 220),
 165      'DarkPurple' => array(88, 0, 192),
 166      'Purple' => array(128, 0, 255),
 167      'LightPurple' => array(168, 88, 255),
 168      'VeryLightPurple' => array(220, 168, 255),
 169  );
 170  
 171  /* <php5> */
 172  
 173  $php = '';
 174  
 175  foreach($colors as $name => $color) {
 176  
 177      list($red, $green, $blue) = $color;
 178  
 179      $php .= '
 180      class aw'.$name.' extends awColor {
 181      
 182  		public function __construct($alpha = 0) {
 183              parent::__construct('.$red.', '.$green.', '.$blue.', $alpha);
 184          }
 185      
 186      }
 187      ';
 188      
 189      if(ARTICHOW_PREFIX !== 'aw') {
 190          $php .= '
 191          class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
 192          
 193          }
 194          ';
 195      }
 196  
 197  }
 198  
 199  eval($php);
 200  
 201  /* </php5> */
 202  /* <php4> --
 203  
 204  $php = '';
 205  
 206  foreach($colors as $name => $color) {
 207  
 208      list($red, $green, $blue) = $color;
 209  
 210      $php .= '
 211      class aw'.$name.' extends awColor {
 212      
 213          function aw'.$name.'($alpha = 0) {
 214              parent::awColor('.$red.', '.$green.', '.$blue.', $alpha);
 215          }
 216      
 217      }
 218      ';
 219      
 220      if(ARTICHOW_PREFIX !== 'aw') {
 221          $php .= '
 222          class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
 223          
 224          }
 225          ';
 226      }
 227  
 228  }
 229  
 230  eval($php);
 231  
 232  -- </php4> */
 233  
 234  ?>


Généré le : Thu Sep 6 14:14:11 2007 par Balluche grâce à PHPXref 0.7