喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 喜悦证交所 | 帮助

RSS 订阅当前论坛  

[北京]代朋友公司招聘PHP高级程序员多名

上一主题 下一主题
 11  1/2  1  2  > 
     
标题: 生成曲線坉的類  
 
meteor_shower
高级会员
Rank: 4
揮刀戲江湖譜寫情緣傳奇


UID 66798
精华 2
积分 957
帖子 897
金钱 927 喜悦币
威望 30
人脉 0
阅读权限 50
注册 2005-9-21
来自 深圳
状态 离线
生成曲線坉的類

類文檔

<?php

    
class LabelFormat
    
{
        var 
$width;
        var 
$precision;
        var 
$specific;
        var 
$vertical;
        var 
$fontsize;
        var 
$fun;

        function 
LabelFormat ($width=0$prec=1$spec="f"$fontsize=3$vert=0$function="")
        {
            
$this->fun=$function;
            
$this->width=$width;
            
$this->precision=$prec;
            
$this->specific=$spec;
            
$this->fontsize=$fontsize;
            
$this->vertical=$vert;
        }

        function 
Out ($value)
        {
            
//$this->fun=$fun;
            
$format_string="%";
            if (
$this->width)
                
$format_string.=$this->width;
            if (
$this->precision)
                
$format_string.=".".$this->precision;
            
$format_string.=$this->specific;
            if (!empty(
$this->fun))
            {
                
$out=call_user_func ($this->fun$value);
                
$wstring=sprintf($format_string$out);
            }
            else
                
$wstring=sprintf($format_string$value);
            return 
$wstring;
        }
    }

    class 
graph2d
    
{

        var 
$image_type;

        var 
$dimx;
        var 
$dimy;

        var 
$xmin;
        var 
$xmax;

        var 
$ymin;
        var 
$ymax;

        var 
$xstep;
        var 
$ystep;

        var 
$xskip;
        var 
$yskip;

        var 
$xformat;
        var 
$yformat;

        var 
$b_red;
        var 
$b_green;
        var 
$b_blue;
        var 
$b_alpha;
        var 
$a_red;
        var 
$a_green;
        var 
$a_blue;
        var 
$a_alpha;

        var 
$is_grid;
        var 
$grid_red;
        var 
$grid_green;
        var 
$grid_blue;
        
//var $grid_style;


        
var $top;
        var 
$left;
        var 
$right;
        var 
$bottom;

        var 
$xlegend;
        var 
$ylegend;
        var 
$title;

        var 
$image;

        function 
graph2d ($image_type$width$height$xleft=0$ytop=0$xright=0$ybottom=0$br=0xFF$bg=0xFF$bb=0xFF$b_alpha=0$ar=0$ag=0$ab=0$a_alpha=0)
        {
            
$this->image_type=$image_type;
            
$this->dimx=(int)$width;
            
$this->dimy=(int)$height;
            
            
$this->b_red=(int)$br;
            
$this->b_green=(int)$bg;
            
$this->b_blue=(int)$bb;

            
$this->a_red=(int)$ar;
            
$this->a_green=(int)$ag;
            
$this->a_blue=(int)$ab;

            
$this->a_alpha=(int)$a_alpha;
            
$this->b_alpha=(int)$b_alpha;

            
$this->left=(int)$xleft;
            
$this->top=(int)$ytop;
            
$this->right=(int)$xright;
            
$this->bottom=(int)$ybottom;

            
$this->xskip=1;
            
$this->yskip=1;

            
$this->xformat=new LabelFormat();
            
$this->yformat=new LabelFormat();

            
$this->xlegend="";
            
$this->ylegend="";
            
$this->title="";

            
$this->is_grid=FALSE;
            
//$this->grid_style=array();

            
$imtype="Content-type: image/".$this->image_type;
            
header ($imtype);
            
$this->image=@imagecreate ($this->dimx$this->dimy);// or die "Cannot initialize new GD Image stream";
        
}

        function 
SetAxisScales ($xmin$xmax$xstep$xskip$ymin$ymax$ystep$yskip)
        {
            
$this->xmin=(double)$xmin;
            
$this->xmax=(double)$xmax;
            
$this->xstep=(double)$xstep;
            
$this->xskip=(int)$xskip;

            
$this->ymin=(double)$ymin;
            
$this->ymax=(double)$ymax;
            
$this->ystep=(double)$ystep;
            
$this->yskip=(int)$yskip;
        }

        function 
SetXLegend ($xleg) { $this->xlegend=$xleg; }

        function 
SetYLegend ($yleg) { $this->ylegend=$yleg; }

        function 
SetTitle ($title) { $this->title=$title; }

        function 
SetLineThickness ($thikness)
        {
             if ( 
is_resource ($this->image) && is_int ($thikness))
                 
imagesetthickness ($this->image$thikness);
        }

        function 
SetGrid($grid$red$green$blue)
        {
            
$this->is_grid=$grid;
            
$this->grid_red=$red;
            
$this->grid_green=$green;
            
$this->grid_blue=$blue;
            
//$this->grid_style=$style;
        
}

        function 
GraphCoord ()
        {
            if (
function_exists("imagecolorallocatealpha"))
            {
                
$background=imagecolorallocatealpha ($this->image$this->b_red$this->b_green$this->b_blue$this->b_alpha);
                
$foreground=imagecolorallocatealpha ($this->image$this->a_red$this->a_green$this->a_blue$this->a_alpha);
            }
            else
            {
                
$background=imagecolorallocate ($this->image$this->b_red$this->b_green$this->b_blue);
                if (
$this->b_alpha)
                    
imagecolortransparent($this->image$background);
                
$foreground=imagecolorallocate ($this->image$this->a_red$this->a_green$this->a_blue);
            }

            
$X=$this->dimx-($this->left+$this->right);
            
$Y=$this->dimy-($this->top+$this->bottom);

            
$scaleX=($this->xmax-$this->xmin)/$X;
            
$scaleY=($this->ymax-$this->ymin)/$Y;

            
$gcolor=imagecolorallocate ($this->image$this->grid_red$this->grid_green$this->grid_blue);
            if (
$this->is_grid)
                
$coord=imagerectangle($this->image$this->left$this->top$this->dimx-$this->right$this->dimy-$this->bottom$gcolor);
            else
                
$coord=imagerectangle($this->image$this->left$this->top$this->dimx-$this->right$this->dimy-$this->bottom$foreground);
            if (!empty(
$this->title))
                
imagestring ($this->image4$this->left+$X/2-strlen($this->title)*imagefontwidth(4)/2$this->top/2-imagefontheight(4)/2$this->title$foreground);
            
$numx=($this->xmax-$this->xmin)/$this->xstep+1;
            
$numy=($this->ymax-$this->ymin)/$this->ystep+1;
            for (
$i=0$i<$numx$i++)
            {
                
$x=($i*$X)/($numx-1)+$this->left;
                if (
$i>&& $i<$numx-1)
                    if (
$this->is_grid)
                        
imageline ($this->image$x$Y+$this->top$x$this->top$gcolor);
                    else
                        
imageline ($this->image$x$Y+$this->top-5$x$Y+$this->top+5$foreground);
                if (
$i%$this->xskip==0)
                {
                    
$xstr=$this->xformat->Out($this->xmin+($i*$X)*$scaleX/($numx-1));
                    if (
$this->xformat->vertical)
                        
imagestringup ($this->image$this->xformat->fontsize$x-imagefontwidth($this->xformat->fontsize), $Y+$this->top+strlen($xstr)*imagefontheight($this->xformat->fontsize)/2+5$xstr$foreground);
                    else
                        
imagestring ($this->image$this->xformat->fontsize$x-strlen($xstr)*imagefontwidth($this->xformat->fontsize)/2$Y+$this->top+imagefontheight($this->xformat->fontsize)/2$xstr$foreground);
                }
            }
            if (!empty(
$this->xlegend))
                
imagestring ($this->image3$this->left+$X/2$this->top+$Y+3*imagefontheight(3)/2$this->xlegend$foreground);
            for (
$i=0$i<$numy$i++)
            {
                
$y=($i*$Y)/($numy-1);
                if (
$i>&& $i<$numy-1)
                    if (
$this->is_grid)
                        
imageline ($this->image$this->left-5$y+$this->top$this->left+$X$y+$this->top$gcolor);
                    else
                        
imageline ($this->image$this->left-5$y+$this->top$this->left+5$y+$this->top$foreground);
                if (
$i%$this->yskip==0)
                {
                    
$ystr=$this->yformat->Out($this->ymin+($i*$Y)*$scaleY/($numy-1));
                    if (
$this->yformat->vertical)
                        
imagestringup ($this->image$this->yformat->fontsize$this->left-imagefontheight($this->yformat->fontsize)-5$Y+$this->top+$this->bottom-$y-3*strlen($ystr)*imagefontwidth($this->yformat->fontsize)/2$ystr$foreground);
                    else
                        
imagestring ($this->image$this->yformat->fontsize$this->left-strlen($ystr)*imagefontwidth($this->yformat->fontsize)-5$Y+$this->top-$y-imagefontheight($this->yformat->fontsize)/2$ystr$foreground);
                }
            }
            if (!empty(
$this->ylegend))
                
imagestringup ($this->image3$this->left/2-3*imagefontheight(3)/2$this->top+$Y/2+strlen($this->ylegend)*imagefontwidth(3)/2$this->ylegend$foreground);
        }

        function 
Draw ($xarray$yarray$r=0$g=0$b=0)
        {
            if (!
is_array($xarray) || !is_array($yarray)) return;

            if (
function_exists("imagecolorallocatealpha"))
            {
                
$background=imagecolorallocatealpha ($this->image$this->b_red$this->b_green$this->b_blue$this->b_alpha);
                
$foreground=imagecolorallocatealpha ($this->image$this->a_red$this->a_green$this->a_blue$this->a_alpha);
            }
            else
            {
                
$background=imagecolorallocate ($this->image$this->b_red$this->b_green$this->b_blue);
                if (
$this->b_alpha)
                    
imagecolortransparent($this->image$background);
                
$foreground=imagecolorallocate ($this->image$this->a_red$this->a_green$this->a_blue);
            }
            
$graphcolor=imagecolorallocate ($this->image$r$g$b);

            
$X=$this->dimx-($this->left+$this->right);
            
$Y=$this->dimy-($this->top+$this->bottom);

            
$scaleX=($this->xmax-$this->xmin)/$X;
            
$scaleY=($this->ymax-$this->ymin)/$Y;

            
$numx=($this->xmax-$this->xmin)/$this->xstep+1;
            
$numy=($this->ymax-$this->ymin)/$this->ystep+1;

            
$nx=count($xarray);
            
$ny=count($yarray);
            
$n=min($nx$ny);

            for (
$i=1$i<$n$i++)
                
imageline($this->image$this->left+($xarray[$i-1]-$this->xmin)/$scaleX$this->top+($this->ymax-$yarray[$i-1])/$scaleY$this->left+($xarray[$i]-$this->xmin)/$scaleX$this->top+($this->ymax-$yarray[$i])/$scaleY$graphcolor);
        }

        function 
ImageOut ($filename)
        {
            if (
strcasecmp ($this->image_type"jpeg")==0)
                
imagejpeg ($this->image$filename100);
            elseif (
strcasecmp ($this->image_type"png")==0)
                
imagepng ($this->image$filename100);
            elseif (
strcasecmp ($this->image_type"gif")==0)
                
imagegif ($this->image$filename100);
            elseif (
strcasecmp ($this->image_type"wbmp")==0)
                
imagewbmp ($this->image$filename100);
        }

        function 
Close ()
        {
            
imagedestroy ($this->image);
        }
    }
?>
2006-3-2 02:41 PM#1
查看资料  发短消息  QQ  顶部
 
meteor_shower
高级会员
Rank: 4
揮刀戲江湖譜寫情緣傳奇


UID 66798
精华 2
积分 957
帖子 897
金钱 927 喜悦币
威望 30
人脉 0
阅读权限 50
注册 2005-9-21
来自 深圳
状态 离线
[推荐阅读] Non-static method
例1

<?php
    
require_once ('graph2d.class.php');

    
$xmin=0.0;
    
$xmax=1.0;
    
$xstep=0.001;

    
$ymin=0.0;
    
$ymax=1.0;
    
$ystep=0.1;

    
$xarr=array();
    
$yarr1=array();
    
$yarr2=array();
    
$yarr3=array();

    
$n=1001;
    for (
$i=0$i<$n$i++)
    {
        
$xarr[$i]=$xmin+$xstep*$i;
        
$yarr1[$i]=$xarr[$i];
        
$yarr2[$i]=$xarr[$i]*$xarr[$i];
        
$yarr3[$i]=sqrt ($xarr[$i]);
    }

    
$test=new graph2d ("jpeg"70035060202040);

    
$test->SetAxisScales ($xmin$xmax0.11$ymin$ymax$ystep1);

    
$test->SetGrid(TRUE0xA00xA00xA0);

    
$test->SetTitle ("Test");
    
$test->SetXLegend ("X");
    
$test->SetYLegend ("Y");

    
$test->GraphCoord();

    
$test->Draw($xarr$yarr10xFF00);

    
$test->Draw($xarr$yarr200xFF0);

    
$test->Draw($xarr$yarr3000xFF);

    
$test->ImageOut("");

    
$test->Close();

?>
2006-3-2 02:42 PM#2
查看资料  发短消息  QQ  顶部
 
meteor_shower
高级会员
Rank: 4
揮刀戲江湖譜寫情緣傳奇


UID 66798
精华 2
积分 957
帖子 897
金钱 927 喜悦币
威望 30
人脉 0
阅读权限 50
注册 2005-9-21
来自 深圳
状态 离线
[推荐阅读] 哪个好
例2

<?php
    
require_once ('graph2d.class.php');

    
$xmin=0.0;
    
$xmax=1.0;
    
$xstep=0.001;

    
$ymin=0.0;
    
$ymax=1.0;
    
$ystep=0.1;

    
$xarr=array();
    
$yarr1=array();
    
$yarr2=array();
    
$yarr3=array();

    
$n=1001;
    for (
$i=0$i<$n$i++)
    {
        
$xarr[$i]=$xmin+$xstep*$i;
        
$yarr1[$i]=$xarr[$i];
        
$yarr2[$i]=$xarr[$i]*$xarr[$i];
        
$yarr3[$i]=sqrt ($xarr[$i]);
    }

    
$test=new graph2d ("jpeg"70035060202040);

    
$test->SetAxisScales ($xmin$xmax0.11$ymin$ymax$ystep1);

    
$test->SetTitle ("Test");
    
$test->SetXLegend ("X");
    
$test->SetYLegend ("Y");

    
$test->GraphCoord();

    
$test->Draw($xarr$yarr10xFF00);

    
$test->Draw($xarr$yarr200xFF0);

    
$test->Draw(<