🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

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

Started by
1 comment, last by Afterlife 22 years, 9 months ago
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
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-
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
Thanks man (I feel so stupid right now )
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-

This topic is closed to new replies.

Advertisement