[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/artichow/php4/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  /**
  11   * Create your colors
  12   *
  13   * @package Artichow
  14   */
  15  class awColor {
  16      
  17      var $red;
  18      var $green;
  19      var $blue;
  20      var $alpha;
  21      
  22      var $resource;
  23      var $color;
  24  
  25      /**
  26       * Build your color
  27       *
  28       * @var int $red Red intensity (from 0 to 255)
  29       * @var int $green Green intensity (from 0 to 255)
  30       * @var int $blue Blue intensity (from 0 to 255)
  31       * @var int $alpha Alpha channel (from 0 to 100)
  32       */
  33  	 function awColor($red, $green, $blue, $alpha = 0) {
  34      
  35          $this->red = (int)$red;
  36          $this->green = (int)$green;
  37          $this->blue = (int)$blue;
  38          $this->alpha = (int)round($alpha * 127 / 100);
  39          
  40      }
  41      
  42      /**
  43       * Return a GDised color
  44       *
  45       * @param resource $resource A GD resource
  46       * @return int
  47       */
  48  	 function getColor($resource) {
  49      
  50          $this->resource = $resource;
  51          
  52          if($this->color === NULL) {
  53      
  54              if($this->alpha === 0 or function_exists('imagecolorallocatealpha') === FALSE) {
  55                  $this->color = imagecolorallocate($this->resource, $this->red, $this->green, $this->blue);
  56              } else {
  57                  $this->color = imagecolorallocatealpha($this->resource, $this->red, $this->green, $this->blue, $this->alpha);
  58              }
  59              
  60          }
  61          
  62          return $this->color;
  63      
  64      }
  65      
  66      /**
  67       * Change color brightness
  68       *
  69       * @param int $brightness Add this intensity to the color (betweeen -255 and +255)
  70       */
  71  	 function brightness($brightness) {
  72      
  73          $brightness = (int)$brightness;
  74      
  75          $this->red = min(255, max(0, $this->red + $brightness));
  76          $this->green = min(255, max(0, $this->green + $brightness));
  77          $this->blue = min(255, max(0, $this->blue + $brightness));
  78      
  79      }
  80      
  81      /**
  82       * Get RGB and alpha values of your color
  83       *
  84       * @return array
  85       */
  86  	 function rgba() {
  87      
  88          return array($this->red, $this->green, $this->blue, $this->alpha);
  89      
  90      }
  91      
  92      /**
  93       * Free resources used for this color
  94       */
  95  	 function free() {
  96      
  97          if($this->resource !== NULL) {
  98      
  99              @imagecolordeallocate($this->resource, $this->color);
 100              $this->resource = NULL;
 101              
 102          }
 103      
 104      }
 105      
 106  	 function php5Destructor() {
 107      
 108          $this->free();
 109      
 110      }
 111  
 112  }
 113  
 114  registerClass('Color');
 115  
 116  $colors = array(
 117      'Black' => array(0, 0, 0),
 118      'AlmostBlack' => array(48, 48, 48),
 119      'VeryDarkGray' => array(88, 88, 88),
 120      'DarkGray' => array(128, 128, 128),
 121      'MidGray' => array(160, 160, 160),
 122      'LightGray' => array(195, 195, 195),
 123      'VeryLightGray' => array(220, 220, 220),
 124      'White' => array(255, 255, 255),
 125      'VeryDarkRed' => array(64, 0, 0),
 126      'DarkRed' => array(128, 0, 0),
 127      'MidRed' => array(192, 0, 0),
 128      'Red' => array(255, 0, 0),
 129      'LightRed' => array(255, 192, 192),
 130      'VeryDarkGreen' => array(0, 64, 0),
 131      'DarkGreen' => array(0, 128, 0),
 132      'MidGreen' => array(0, 192, 0),
 133      'Green' => array(0, 255, 0),
 134      'LightGreen' => array(192, 255, 192),
 135      'VeryDarkBlue' => array(0, 0, 64),
 136      'DarkBlue' => array(0, 0, 128),
 137      'MidBlue' => array(0, 0, 192),
 138      'Blue' => array(0, 0, 255),
 139      'LightBlue' => array(192, 192, 255),
 140      'VeryDarkYellow' => array(64, 64, 0),
 141      'DarkYellow' => array(128, 128, 0),
 142      'MidYellow' => array(192, 192, 0),
 143      'Yellow' => array(255, 255, 2),
 144      'LightYellow' => array(255, 255, 192),
 145      'VeryDarkCyan' => array(0, 64, 64),
 146      'DarkCyan' => array(0, 128, 128),
 147      'MidCyan' => array(0, 192, 192),
 148      'Cyan' => array(0, 255, 255),
 149      'LightCyan' => array(192, 255, 255),
 150      'VeryDarkMagenta' => array(64, 0, 64),
 151      'DarkMagenta' => array(128, 0, 128),
 152      'MidMagenta' => array(192, 0, 192),
 153      'Magenta' => array(255, 0, 255),
 154      'LightMagenta' => array(255, 192, 255),
 155      'DarkOrange' => array(192, 88, 0),
 156      'Orange' => array(255, 128, 0),
 157      'LightOrange' => array(255, 168, 88),
 158      'VeryLightOrange' => array(255, 220, 168),
 159      'DarkPink' => array(192, 0, 88),
 160      'Pink' => array(255, 0, 128),
 161      'LightPink' => array(255, 88, 168),
 162      'VeryLightPink' => array(255, 168, 220),
 163      'DarkPurple' => array(88, 0, 192),
 164      'Purple' => array(128, 0, 255),
 165      'LightPurple' => array(168, 88, 255),
 166      'VeryLightPurple' => array(220, 168, 255),
 167  );
 168  
 169  
 170  
 171  $php = '';
 172  
 173  foreach($colors as $name => $color) {
 174  
 175      list($red, $green, $blue) = $color;
 176  
 177      $php .= '
 178      class aw'.$name.' extends awColor {
 179      
 180          function aw'.$name.'($alpha = 0) {
 181              parent::awColor('.$red.', '.$green.', '.$blue.', $alpha);
 182          }
 183      
 184      }
 185      ';
 186      
 187      if(ARTICHOW_PREFIX !== 'aw') {
 188          $php .= '
 189          class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
 190          
 191          }
 192          ';
 193      }
 194  
 195  }
 196  
 197  eval($php);
 198  
 199  
 200  
 201  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics