• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Little math problem

M

Midastouch

Guest
Hello everyone,

I have a temperature which can have take a minimum value at -25°C and a maximum at 50°C.
I want to convert my temperature value in a percentage in order to my -25°C is 0% and my 50 °C is 100%.

The aim for me is to use : merge_colour(col1, col2, amount); to represent the temperatures variation in a map.

Can you help me?
 

FrostyCat

Redemption Seeker
Your original range is -25 to 50.

Adding 25 gives a new range of 0 to 75.

Dividing by 75 gives the final desired range of 0 to 1.

I strongly suggest that you get your math in line and familiarize yourself with linear interpolation. For people who attempt game development without linear interpolation, their stuff tends to look like crap because of a lack of smooth transitions, and they waste hours on routine problems that people who do know it finish in seconds.
 

kburkhart84

Firehammer Games
I would make a function out of it, which would be handy for other situations that need it. See this post for it(created by FrostyCat FYI).

You are basically mapping a range to another range, sort of a reverse LERP of sorts. So halfway between the first two values would map to halfway between the second two values. You can then use that mapping to do a LERP between your color choices.
 
Top