invisionx Posted July 21, 2007 Share Posted July 21, 2007 I got this script off of a site right now can't remember but i want to make it so that the colors are not random for each person <?php class Pie { var $imageWidth = 400; var $imageHeight = 300; var $bgR = 91; var $bgG = 91; var $bgB = 91; var $title = "1st Fleet Pie Chart"; function create($varDesc, $varValues) { Header("Content-type: image/png"); $image = ImageCreate($this->imageWidth, $this->imageHeight); $bgcolor = ImageColorAllocate($image, $this->bgR, $this->bgG, $this->bgB); $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 91, 91, 91); ImageFill($image, 0, 0, $bgcolor); // here is where random color comes from.. $num = 0; foreach($varDesc as $v) { $r = rand (0, 255); $g = rand (0, 255); $b = rand (0, 255); $sliceColors[$num] = ImageColorAllocate($image, $r, $g, $b); $num++; } // now $num has the number of elements // draw the box ImageLine($image, 0, 0, $this->imageWidth - 1, 0, $black); ImageLine($image, $this->imageWidth - 1, 0, $this->imageWidth - 1, $this->imageHeight - 1, $black); ImageLine($image, $this->imageWidth - 1, $this->imageHeight - 1, 0, $this->imageHeight - 1, $black); ImageLine($image, 0, $this->imageHeight - 1, 0, 0, $black); $total = 0; for ($x = 0; $x < $num; $x++) { $total += $varValues[$x]; } // convert each slice into corresponding percentage of 360-degree circle for ($x = 0; $x < $num; $x++) { $angles[$x] = ($varValues[$x] / $total) * 360; } for($x = 0; $x < $num; $x++) { // calculate and draw arc corresponding to each slice ImageArc($image, $this->imageWidth/4, $this->imageHeight/2, $this->imageWidth/3, $this->imageHeight/3, $angle, ($angle + $angles[$x]), $sliceColors[$x]); $angle = $angle + $angles[$x]; $x1 = round($this->imageWidth/4 + ($this->imageWidth/3 * cos($angle*pi()/180)) / 2); $y1 = round($this->imageHeight/2 + ($this->imageHeight/3 * sin($angle*pi()/180)) / 2); // demarcate slice with another line ImageLine($image, $this->imageWidth/4, $this->imageHeight/2, $x1, $y1, $sliceColors[$x]); } // fill in the arcs $angle = 0; for($x = 0; $x < $num; $x++) { $x1 = round($this->imageWidth/4 + ($this->imageWidth/3 * cos(($angle + $angles[$x] / 2)*pi()/180)) / 4); $y1 = round($this->imageHeight/2 + ($this->imageHeight/3 * sin(($angle + $angles[$x] / 2)*pi()/180)) / 4); ImageFill($image, $x1, $y1, $sliceColors[$x]); $angle = $angle + $angles[$x]; } // put the desc strings ImageString($image, 5, $this->imageWidth/2, 60, "Legend", $black); for($x = 0; $x < $num; $x++) { $fl = sprintf("%.2f", $varValues[$x] * 100 / $total); $str = $varDesc[$x]." (".$fl."%)"; ImageString($image, 3 , $this->imageWidth/2, ($x + 5) * 20, $str, $sliceColors[$x]); } // put the title ImageString($image, 5, 20, 20, $this->title, $white); ImagePng($image); ImageDestroy($image); } } $pie = new Pie; if(isset($width)) { $pie->imageWidth = $width; } if(isset($height)) { $pie->imageHeight = $height; } if(isset($title)) { $pie->title = $title; } $varDesc = explode(",", $desc); $varValues = explode(",", $values); $pie->create($varDesc, $varValues); ?> can someone help me please thank you invisionx Quote Link to comment Share on other sites More sharing options...
ss32 Posted July 21, 2007 Share Posted July 21, 2007 well you would just change those $r, $g, and $b values to whatever you want in the loop, its kinda simple. additionally, you could use a formula in order to do like a gradient or rainbow of colors, if you wish. Quote Link to comment Share on other sites More sharing options...
decypher Posted July 21, 2007 Share Posted July 21, 2007 $r = rand (0, 255); $g = rand (0, 255); $b = rand (0, 255); That code is the problem...just change them to what you want Quote Link to comment Share on other sites More sharing options...
invisionx Posted July 21, 2007 Author Share Posted July 21, 2007 thats random tho and also there are like 4 or 5 different names im using and just that one little color script does all of them.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.