Uneven distrobution instead of normal map()


#1

If you use something like map(n,0,100, 0,200), it will map things evenly. 0 maps to 0, 100 maps to 200, and each integer in-between is evenly spaced. But what if you don’t want the mapping to be as even? As in, when lower numbers get mapped they are closer together, and higher numbers are further away from each other. It seems like it should be a log or exponential kind of growth…or something?

I know I’m not explaining this the best, but I hope this resonates with someone, and they can send me down the right path.


#2

@noFun yes it should be fun!

map is just a prepared function to do a often occurring job for you.

so you have a special job? you write the function.
you could start to just do the “map” thing again,
( pls. show it here )
and from there start to do a “maplog” version.


#3

But that is the trouble, I don’t know what the function or math is to make that happen.


#4

i help you with the

framework
int Nin = 33;
float Nout;

float my_map(float n, float inlow, float inhigh, float outlow, float outhigh) {
  float in_range = 0;
// you do the first math and show us
  return(in_range);
}

void setup() {
  size(100, 100);
  Nout = my_map(Nin, 0, 100, 0, 200);
  println("Nin: "+Nin+" my_map "+Nout);
}

void draw() {
}

inthere you start with some math

and as we are using processing we must have some minimal graphic show

int Nin = 33;
float Nout;

float my_map(float n, float inlow, float inhigh, float outlow, float outhigh) {
  float in_range = n;
  return(in_range);
}

void setup() {
  size(120, 220);
  Nout = my_map(Nin, 0, 100, 0, 200);
  println("Nin: "+Nin+" my_map "+Nout);
}

void draw_graph() {
  for ( int i=0;i<101;i++){
    int posx = i+10;
    int posy = 210 - int(my_map(i, 0, 100, 0, 200));
    if( i == Nin ) { stroke(200,0,0); } else { stroke(0); }
    line(posx,210,posx,posy);
  }
}

void draw() {
  draw_graph(); 
}

if you want play p5.js here