map() function

edited June 2016 in Questions about Code

Hello,

I am trying to figure out how this map() function works... but I just don't get it. Maybe you guys can help me out..

For example:

float a;

void setup(){
  size(300, 300);
}

void draw(){
  a= 50;
  a=map(a, -100, 100, 0, 2000);
}

How big wil "A" be after the mapping and why?

Tagged:

Answers

  • edited June 2016 Answer ✓

    just println(a); to find out...

    the input values go from -100 to 100. 50 is 3/4s of the way along that line so the output is 3/4s of the way along the line from 0 to 2000 (= 1500)

    -100--------0000--------+100
                        ^50
    0000--------1000--------2000
                        ^1500
    
  • Thx allot!

    so if A would be 0. The output would be 1000?

  • Answer ✓

    try it!

    (yes)

  • You sir, are my hero.. I will try it.

    Thank you!

Sign In or Register to comment.