How to scale an input number range ?

NikNok
Messages
2
Reaction score
0
Hello all,

I'm a 3D graphist trying to deal with particles motions and attributes for visual FX

I have a surface mapped with a black and white picture. Those different grey values gives me a x value inbetween 0(min) and 255(max). Particles are shot from this plane and from random positions and get this point value x based on where they have spawn on the surface, so based on the value of the gray pixel they spawn onto.

I want to play on the speed, size, and more attributes of those particles based on this grey value x.

I need to define a custom minimum and a custom maximum value. So basically, I need to go from :

0 <= x <= 255

to y(min) <= x <= z(max) which can be else -50 <= x <= 50 or else 33.25 <= x <= 68.1

The thing is I want to keep the proportionality in my values
So it is not a clamping function, like

if x > z then x = z
if x < y then z = y

It would be more of a scaling function. Is it ??
Sounds to me like changing the limits of my range (function ?)

It is actually the level function of photoshop,whitout the gray marker
I can right down a script to apply to my particles behavior.

Am I clear enough ? Can you help me ?
 
Last edited:
Physics news on Phys.org
NikNok said:
Hello all,
I need to define a custom minimum and a custom maximum value. So basically, I need to go from :

0 <= x <= 255

to y(min) <= x <= z(max) which can be else -50 <= x <= 50 or else 33.25 <= x <= 68.1

Not sure if I totally understand the problem. But can you just do an addition and a multiplication on each x value?

If the range of the original x's was:
0 <= x <= 255
And you make x* = (x-128) * 0.5
then
-64 <= x* <= 63.5
 
Figured it out, what I was looking for was actually :

NC = C/(M-m)*(NM-Nm)+Nm


NC = new color
C= color imput
M=maximum
m=minimum
NM=new max
Nm=new min

Thanks for paying attention to this, cheers
 
Back
Top