日期:2014-05-17 浏览次数:20472 次
<?php //error_reporting(E_ALL ^ E_NOTICE); class Graph { /** * 伪3D绘图类 */ var $im; var $type = "gif"; // png,gif,jpeg,wbmp var $xo; var $yo; var $color; var $fillcolor; var $filldarkcolor; var $filltype = true; var $orgx; var $orgy; var $viewx; var $viewy; var $winx; var $winy; var $extx = 1; var $exty = -1; var $ksin; var $kcos; function Graph() { if(func_num_args() == 2) $this->create(func_get_arc(0),func_get_arc(1)); else $this->create(400,300); } /** * 在($x,$y)处画点 */ function pixel($x,$y) { $p = $this->get_view($x,$y); imagesetpixel($this->im,$p['x'],$p['y'],$this->color); $this->xo = $p['x']; $this->yo = $p['y']; } /** * 移动到($x,$y)处 */ function moveto($x,$y) { $p = $this->get_view($x,$y); $this->xo = $p['x']; $this->yo = $p['y']; } /** * 从($x1,$y1)到($x2,$y2)处画线 */ function line($x1,$y1,$x2,$y2) { $p1 = $this->get_view($x1,$y1); $p2 = $this->get_view($x2,$y2); imageline($this->im,$p1['x'],$p1['y'],$p2['x'],$p2['y'],$this->color); } /** * 从当前位置到($x,$y)处画线 */ function lineto($x,$y) { $p = $this->get_view($x,$y); imageline($this->im, $this->xo, $this->yo, $p['x'], $p['y'], $this->color); $this->xo = $p['x']; $this->yo = $p['y']; } /** * 设置当前颜色 */ function color($clr) { $r = ($clr>>16) & 0xff; $g = ($clr>>8) & 0xff; $b = ($clr) & 0xff; $this->color = ImageColorAllocate($this->im, $r,$g,$b); $this->fillcolor = ImageColorAllocate($this->im, $r,$g,$b); $this->filldarkcolor = ImageColorAllocate($this->im, $r/2,$g/2,$b/2); return $this->color; } /** * 设置当前充填颜色 */ function fillcolor($clr) { $r = ($clr>>16) & 0xff; $g = ($clr>>8) & 0xff; $b = ($clr) & 0xff; $this->fillcolor = ImageColorAllocate($this->im, $r,$g,$b); return $this->fillcolor; } /** * 创建GD句柄并设置坐标系 */ function create($x,$y) { $this->im = imagecreatetruecolor($x,$y); imageantialias($this->im, 1); imagefill($this->im, 0, 0, $this->color(0xffffff)); $this->viewx = $x-1; $this->viewy = -($y-1); $this->winx = $x; $this->winy = $y; $this->orgx = 0; $this->orgy = 0;//$y; $this->colors = $this->color(0xffffff); settype($this->ksin,"double"); settype($this->kcos,"double"); $this->ksin = sin(deg2rad(0)); $this->kcos = cos(deg2rad(0)); } /** * 坐标映射 */ function get_view($x,$y) { $this->xo = $x*$this->kcos - $y*$this->ksin; $this->yo = $x*$this->ksin + $y*$this->kcos; $p['x'] = ($this->xo + $this->orgx)*($this->viewx/$this->winx); $p['y'] = ($this->yo + $this->orgy)*($this->viewy/$this->winy)-$this->viewy; return $p; } /** * 设置限度 */ function set_ext($x,$y=0) { $this->winx = $x; if($y == 0) { $this->winy = - $x * $this->viewy / $this->viewx; }else { $this->winy = $y; } } /** * 设置旋转角 */ function set_r($p) { $this->ksin = sin(deg2rad($p)); $this->kcos = cos(