PDA

Volledige versie bekijken : [gd][diagram][3d effect] loopt niet 'smooth'


josko
%Europe/Berlin %943 %2006, 22:39
hoi jongens. ik heb het volgende script gemaakt:
het is in php4, met de gd library.

ik moet voor een project diagrammen toevoegen,
maar ik krijg er een probleempje bij.
dit is het script:
<?php
class diagram
{
var $labels;
var $percen;
var $_count;
var $numbers;
var $root;

var $title;

function diagram( $labels, $percents, $title)
{
/*
Image:
- margin: 50px;

diagram at: 50, 50

diagram - normal width x height
300 x 300
diagram - expansion width x height
300 x 350

image height:
diagram: 350 + margetop, margebottom.
imageheight: 450 + 25x, where x = number of labels;
*/
$this->title = $title;
$imageHeight = 450 + count($labels) * 25;

$this->root = imagecreate( 400, $imageHeight );
imagecolorallocate( $this->root, 0xFF, 0xFF, 0xFF );

$this->labels = array();
$this->labels = $labels;

$this->percen = array();
$this->percen = $percents;

$this->_count = count($labels);

$this->drawpie();
}
function drawpie()
{
$totalDegrees = 0;
$colours = array();

for( $r = 0; $r <= 0xF; $r += 3)
{
$colours[ $r ] = array();
for( $g = 0; $g <= 0xF; $g += 3)
{
$colours[ $r ][ $g ] = array();
for( $b = 0; $b <= 0xF; $b += 3)
{
$colours[$r][ $g ][ $b ] = dechex( $r ).dechex( $r ).dechex( $g ).dechex( $g ).dechex( $b ).dechex( $b );
}
}
}
for( $a = 0; $a < $this->_count; $a++)
{
$rN = rand( 0, 5 )*3;
$gN = rand( 0, 5 )*3;
$color = $this->allocate( $colours[ $rN ][ $gN][6] );
$thisDegrees = $this->percen[ $a ] / 100 * 360;
$thisDegrees = $totalDegrees + round($thisDegrees);
for( $cy = 210; $cy >= 200; $cy-- )
{
imagefilledarc( $this->root, 200, $cy, 300, 150, $totalDegrees, $thisDegrees, $color, IMG_ARC_PIE);
}

$totalDegrees = $thisDegrees;
$this->numbers[$a] = $colours[ $rN ][ $gN ][0];
}
$totalDegrees = 0;
for( $a = 0; $a < $this->_count; $a++)
{
$color = $this->allocate( $this->numbers[ $a ] );
$thisDegrees = $this->percen[ $a ] / 100 * 360;
$thisDegrees = $totalDegrees + round($thisDegrees);

imagefilledarc( $this->root, 200, 200, 300, 150, $totalDegrees, $thisDegrees, $color, IMG_ARC_PIE);

$totalDegrees = $thisDegrees;
}

$color = $this->allocate( "AFD34D");
imagefilledrectangle( $this->root, 0,0, 400, 40, $color );
imageline( $this->root, 0, 40, 400, 40, $this->allocate( "000000" ));

//i want some star next to the title ... :)
$points = array(
12, 12, // Point 1 (x, y)
6, 50, // Point 2 (x, y)
14, 14, // Point 3 (x, y)
50, 6, // Point 4 (x, y)
12, 10, // Point 5 (x, y)
7, 4 // Point 6 (x, y)
);
imagefilledpolygon( $this->root, $points, 6, $this->allocate('FFFFFF'));

for( $pos = 0, $a = 0; $pos <= strlen( $this->title ); $pos += 40, $a++)
{
$text = substr( $this->title, $pos, 40 );
$y = 10 + 12*$a;
imagestring( $this->root, 100, 20, $y, $text, $this->allocate('000000'));
}

imagearc( $this->root, 200, 200, 300, 150, 0, 360, $this->allocate( '000000' ));
imagearc( $this->root, 200, 210, 300, 150, 0, 180, $this->allocate( '000000' ));


for( $a = 0; $a < $this->_count; $a++)
{
// (percent)colorlabel
$color = $this->numbers[ $a ];
$color = $this->allocate( $color );
$yPos = 350 + 12 * $a;
imagestring( $this->root, 5, 50, $yPos , '('. round( $this->percen[$a], 1 ).' %)', $this->allocate( '000000' ));
imagefilledrectangle( $this->root, 120, $yPos, 130, $yPos+10, $color );
imagestring( $this->root, 5, 140, $yPos , substr( $this->labels[$a], 0, 25 ), $this->allocate( '000000' ));
}
}

function image()
{
header('content-type: image/png');
imagepng( $this->root );
}
function allocate( $htmlcolor )
{
$red = substr( $htmlcolor, 0, 2 );
$green = substr( $htmlcolor, 2, 2 );
$blue = substr( $htmlcolor, 4, 2 );
return imagecolorallocate( $this->root, hexdec( $red ), hexdec( $green ), hexdec( $blue ));
}

}
$blaat = new diagram( array('label1', 'label2', 'label3', 'label4', 'label5'), array( 12.5 , 13.5 , 14, 25, 35 ), 'de namen van de labels zijn gevonden, maar wat zijn deze labels?' );
$blaat->image();

?>

in de bijlage staat een image die eruit komt. let hierop bij de scheiding in 3d bij label 3 en label 4.

Ik heb al verschillende dingen geprobeerd, maar kan mijn foutje niet vinden. aan de andere kant verloopt het foutloos (dwz de rechterkant :) )

edit - heb het even geaccentueerd 8)

ik zal vraag twee ook alvast stellen
ik gebruik nu de IMG_ARC_PIE. als ik een outline wil, staat er gebruik IMG_ARC_NOFILL en IMG_ARC_EDGED. ik heb in de comments gevonden dat je dat aanroept als
IMG_ARC_NOFILL|IMG_ARC_EDGED. maar dit geeft geen outline :(
hoe doe ik dit?

josko
%Europe/Berlin %967 %2006, 23:13
bernardV heeft uitgevogeld dat het komt omdat je het vlak telkens over tekend.