# Processing mapping function - help

**URL:** <https://discourse.processing.org/t/processing-mapping-function-help/24463>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 9, 2020, 12:07pm UTC](https://discourse.processing.org/t/processing-mapping-function-help/24463 "2020-10-09T12:07:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ellie98](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@Ellie98](https://discourse.processing.org/u/Ellie98)\
**Post date:** [October 9, 2020, 12:07pm UTC](https://discourse.processing.org/t/processing-mapping-function-help/24463/1 "2020-10-09T12:07:07Z")

</div>

Hello,  
I have to code 2 circles that are following the mouse. But the red one stays inside the square and I have to do it with the map() function but I don’t really understand it. It’s not working. Could someone help me out?  
Thanks in advance!

```auto
void setup() {
  surface.setTitle("Mapping");
  size(600, 600);
  surface.setLocation(CENTER, CENTER);
}

void draw() {
  background(0);
  stroke(255);

  fill(255, 255, 255);
  circle(mouseX, mouseY, 20);
  mouseMoved();
  text("Maus X/Y:"+mouseX+"/"+mouseY, 250, 300);

  fill(255, 0, 0);
  float col = map(mouseX, 300, 500, 300, 500);
  circle(mouseX, mouseY, 20);
  mouseMoved();
  text("map to:"+mouseX+"/"+mouseY, 255, 320);

  rectMode(CENTER);
  noFill();
  rect(300, 300, 400, 400);
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 9, 2020, 12:28pm UTC](https://discourse.processing.org/t/processing-mapping-function-help/24463/2 "2020-10-09T12:28:22Z")

</div>

> [@Ellie98](#):
>
> float col = map(mouseX, 300, 500, 300, 500);

Take a look at the example in the references:

[https://processing.org/reference/map\_.html](https://processing.org/reference/map_.html)

Please format your code as a courtesy to the community:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

`:)`
