Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Afterlife

Need an algorithm for converting 0-n to 0-255

This topic is 6209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

distance is 0-n, I need to convert the distance to 0-255. If I could I would do it like this for example: increasement=256/max_distance;
  for(x=0;x<max_distance;x++)
color=makecol(r+=increasement,g+=inc..,b+=...);  
But I can''t in this case. I need it to be somehow check with the current distance. Here''s what I''m trying to do with a circle:
  
if(x<sqrt(rad*rad-(y*y))) //if the current coordinate is within the circle (adjustable center not implemented yet, it''s 0,0 currently)

{
dist=(int)(sqrt((float)(y*y+x*x))); //dinstance from 0,0

red+= 255 - //<-distance modifier here = distance somehow converted to 0-255

// 255 - might also be 0 + depending on the way that the distance is converted

// I thought it would be easier to make it so that the dist. modifier would be 255 when distance is the max_distance(=the radius of the circle), hence 255 - dist_mod

  
I know this is an easy question, but my brains are seriously jammed atm and I can''t figure out it by myself right now. So any help would be appritiated. thank you

Share this post


Link to post
Share on other sites
Advertisement
  
double multiplier = 256/n;

now if n were say 128.....the multiplier would be 2
so any distance would be mutliplied by 2 to get the distance in terms of 0 to 255


"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!