Calculating a percentage based on a 0.01 variable?

Non-platform specific questions.

Calculating a percentage based on a 0.01 variable?

Postby Hblade » Tue Dec 15, 2009 9:42 pm

Okay the title is confusing I know but I'm trying to find out how I can convert something. I have a double variable that holds a maximum of 1, when it's above 1, it deletes an actor.

What I'm trying to do is, how would I..

Aha, I know a better way of showing you what I mean
Okay, say I wanted to make the "Opacity" code instead of using transp all the time, how would I make the 255 numbers of the opacity match up to the transp's maximum of 1?

For example if you do transp = 255; the darn thing will be SUPER transparent :P... so if you were to make transp = opacity, then it would fail. So how would I get the percentage of "transp" using opacity?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Calculating a percentage based on a 0.01 variable?

Postby pyrometal » Tue Dec 15, 2009 9:53 pm

Code: Select all
transp = 1 - (double)opacity / 255;


Note that "opacity" is a measure of how much material blocks light, while trnasparency is a measure of how much a materiale allows light to pass through. Therefore they describe the same property but in reverse perspective, therefore you should invert the behavior (1 - opacity).
SPRITE WARRIOR:
Free, open-source & crossplatform pixel art editor (currently under construction).
User avatar
pyrometal
 
Posts: 706
Joined: Wed Nov 28, 2007 4:07 am
Location: Kingston, ON, Canada
Score: 86 Give a positive score

Re: Calculating a percentage based on a 0.01 variable?

Postby Hblade » Tue Dec 15, 2009 9:54 pm

Thanks :D It worked
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Calculating a percentage based on a 0.01 variable?

Postby pyrometal » Tue Dec 15, 2009 9:58 pm

Don't forget the points! :P I did help you out a lot today. Haha, anyway, have a good one!
SPRITE WARRIOR:
Free, open-source & crossplatform pixel art editor (currently under construction).
User avatar
pyrometal
 
Posts: 706
Joined: Wed Nov 28, 2007 4:07 am
Location: Kingston, ON, Canada
Score: 86 Give a positive score

Re: Calculating a percentage based on a 0.01 variable?

Postby Hblade » Tue Dec 15, 2009 10:00 pm

did ^.^
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron