Adding a Max to a graphic bar[topic solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Adding a Max to a graphic bar[topic solved]

Post by SirChick »

I have a bar which i need to change its max using fields from my table but i need the size and height to be the same..example of what i mean:

Max E - 100
Current E - 50
Green will be half way on the bar.

Max E - 150 (still the same length physically how ever as the 100 E bar)
Current E - 50
Green will be a third of the way up on the bar.


so i have:

maxE and currentE i need the width and height always at 76 wide and 5 height. But the green to red need to be scalled differently if maxE is larger.


this is what i got so far:

Code: Select all

//the two fields from user table set as variables
$MaxEnergy = $row["MaxEnergy"];
$CurrentEnergy = $row["CurrentEnergy"];

$height = 5;
$width = 76;
$im = Imagecreatetruecolor($width, $height);
$red = Imagecolorallocate($im, 400, 0, 10);
$green = Imagecolorallocate($im, 0, 400, 10);
imagefill($im, 0, 0, $red);
imagefilledrectangle($im, 0, 0, $CurrentEnergy, $height, $green);
header("Content-type: image/png");
Imagepng($im);
Imagedestroy($im);
the problem at the moment is im unsure on where i should put my "Maximum E " into the script for it to work the way i need it to?
Last edited by SirChick on Sun Aug 19, 2007 1:09 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Generally...

Code: Select all

($CurrentEnergy / $MaxEnergy) * $MaxWidth;
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post by SirChick »

eh? :S

what would that equal ? The amount of current E ?

EDIT i understand now. got it working thankyou :)
Post Reply