📄 jpgraph_gradient.php
字号:
<?php
class Gradient
{
private $img = null;
private $numcolors = 100;
public function Gradient( &$img )
{
$this->img = $img;
}
public function SetNumColors( $aNum )
{
$this->numcolors = $aNum;
}
public function FilledRectangle( $xl, $yt, $xr, $yb, $from_color, $to_color, $style = 1 )
{
switch ( $style )
{
case GRAD_VER :
do
{
$steps = round( abs( $xr - $xl ) );
$delta = $xl <= $xr ? 1 : -1;
$this->GetColArray( $from_color, $to_color, $steps, $colors, $this->numcolors );
$i = 0;
$x = $xl;
for ( ; $i < $steps; ++$i, )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $x, $yt, $x, $yb );
$x += $delta;
break;
}
} while ( 1 );
case GRAD_HOR :
do
{
$steps = round( abs( $yb - $yt ) );
$delta = $yt <= $yb ? 1 : -1;
$this->GetColArray( $from_color, $to_color, $steps, $colors, $this->numcolors );
$i = 0;
$y = $yt;
for ( ; $i < $steps; ++$i, )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $xl, $y, $xr, $y );
$y += $delta;
break;
}
} while ( 1 );
case GRAD_MIDHOR :
$steps = round( abs( $yb - $yt ) / 2 );
$delta = $yt <= $yb ? 1 : -1;
$this->GetColArray( $from_color, $to_color, $steps, $colors, $this->numcolors );
$y = $yt;
$i = 0;
for ( ; $i < $steps; ++$i )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $xl, $y, $xr, $y );
$y += $delta;
}
--$i;
if ( abs( $yb - $yt ) % 2 == 1 )
{
--$steps;
}
$j = 0;
for ( ; $j < $steps; ++$j, --$i )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $xl, $y, $xr, $y );
$y += $delta;
}
$this->img->Line( $xl, $y, $xr, $y );
break;
case GRAD_MIDVER :
$steps = round( abs( $xr - $xl ) / 2 );
$delta = $xl <= $xr ? 1 : -1;
$this->GetColArray( $from_color, $to_color, $steps, $colors, $this->numcolors );
$x = $xl;
$i = 0;
for ( ; $i < $steps; ++$i )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $x, $yb, $x, $yt );
$x += $delta;
}
--$i;
if ( abs( $xr - $xl ) % 2 == 1 )
{
--$steps;
}
$j = 0;
for ( ; $j < $steps; ++$j, --$i )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $x, $yb, $x, $yt );
$x += $delta;
}
$this->img->Line( $x, $yb, $x, $yt );
break;
case GRAD_WIDE_MIDVER :
do
{
$diff = round( abs( $xr - $xl ) );
$steps = floor( abs( $diff ) / 3 );
$firststep = $diff - 2 * $steps;
$delta = $xl <= $xr ? 1 : -1;
$this->GetColArray( $from_color, $to_color, $firststep, $colors, $this->numcolors );
$x = $xl;
$i = 0;
for ( ; $i < $firststep; ++$i )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $x, $yb, $x, $yt );
$x += $delta;
}
--$i;
$this->img->current_color = $colors[$i];
$j = 0;
for ( ; $j < $steps; ++$j )
{
$this->img->Line( $x, $yb, $x, $yt );
$x += $delta;
}
$j = 0;
for ( ; $j < $steps; ++$j, --$i, )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $x, $yb, $x, $yt );
$x += $delta;
break;
}
} while ( 1 );
case GRAD_WIDE_MIDHOR :
do
{
$diff = round( abs( $yb - $yt ) );
$steps = floor( abs( $diff ) / 3 );
$firststep = $diff - 2 * $steps;
$delta = $yt <= $yb ? 1 : -1;
$this->GetColArray( $from_color, $to_color, $firststep, $colors, $this->numcolors );
$y = $yt;
$i = 0;
for ( ; $i < $firststep; ++$i )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $xl, $y, $xr, $y );
$y += $delta;
}
--$i;
$this->img->current_color = $colors[$i];
$j = 0;
for ( ; $j < $steps; ++$j )
{
$this->img->Line( $xl, $y, $xr, $y );
$y += $delta;
}
$j = 0;
for ( ; $j < $steps; ++$j, --$i, )
{
$this->img->current_color = $colors[$i];
$this->img->Line( $xl, $y, $xr, $y );
$y += $delta;
break;
}
} while ( 1 );
case GRAD_LEFT_REFLECTION :
do
{
$steps1 = round( 0.3 * abs( $xr - $xl ) );
$delta = $xl <= $xr ? 1 : -1;
$from_color = $this->img->rgb->Color( $from_color );
$adj = 1.4;
[exception occured]
================================
Exception code[ C0000005 ]
Compiler[ 00385B30 ]
Executor[ 00386038 ]
OpArray[ 0096E6F0 ]
File< D:\MYOA08\php-de\MYOA08\webroot\inc\jpgraph3\jpgraph_gradient.php >
Class< Gradient >
Function< FilledRectangle >
Stack[ 00145AE0 ]
Step[ 7 ]
Offset[ 485 ]
LastOffset[ 1095 ]
485 MUL [-] 0[0] $Tmp_26 - $Tmp_27 - $Tmp_28
================================
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -