Below you may find some sample PHP Codes :
Chart Demo :
<?php
$myImage = ImageCreate(300,300);
$white = ImageColorAllocate ($myImage, 255, 255, 255);
$red = ImageColorAllocate ($myImage, 255, 0, 0);
$green = ImageColorAllocate ($myImage, 0, 255, 0);
$blue = ImageColorAllocate ($myImage, 0, 0, 255);
$lt_red = ImageColorAllocate($myImage, 255, 150, 150);
$lt_green = ImageColorAllocate($myImage, 150, 255, 150);
$lt_blue = ImageColorAllocate($myImage, 150, 150, 255);
for ($i = 120;$i > 100;$i--) {
ImageFilledArc ($myImage, 100, $i, 200, 150, 0, 90, $lt_red, IMG_ARC_PIE);
ImageFilledArc ($myImage, 100, $i, 200, 150, 90, 180, $lt_green, IMG_ARC_PIE);
ImageFilledArc ($myImage, 100, $i, 200, 150, 180, 360, $lt_blue, IMG_ARC_PIE);
}
ImageFilledArc($myImage, 100, 100, 200, 150, 0, 90, $red, IMG_ARC_PIE);
ImageFilledArc($myImage, 100, 100, 200, 150, 90, 180 , $green, IMG_ARC_PIE);
ImageFilledArc($myImage, 100, 100, 200, 150, 180, 360 , $blue, IMG_ARC_PIE);
header ("Content-type: image/png");
ImagePNG($myImage);
ImageDestroy($myImage);
?>
Pattern Demo :
<?php
class ClassFactory{
private $registeredClasses = array();
static private $instance = NULL;
private function __construct() {}
static function getInstance(){
if(self::$instance == NULL){
self::$instance = new ClassFactory();
}
return self::$instance;
}
function registerClass($id, $creator_func){
$this->registeredClasses[$id] = $creator_func;
}
function createObject($id, $args) {
if(!isset($this->registeredClasses[$id])){
return(NULL);
}
return($this->registeredClasses[$id]($args));
}
}
function MyClassCreator(){
return "creator";
}
$factory = ClassFactory::getInstance();
$factory->registerClass(1, "MyClassCreator");
$instance = $factory->createObject(1, array());
?>
No comments:
Post a Comment