> For the complete documentation index, see [llms.txt](https://learnpython.strivemath.com/p5-python-web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnpython.strivemath.com/p5-python-web/reference/math/linmap.md).

# linmap()

## Example

<figure><img src="/files/tf5XKjTI6uBKI9HGMsRr" alt=""><figcaption></figcaption></figure>

```python
  # value to be mapped from the first range
  x1 = round(min1+(max1-min1)*sin(frameCount/10)**2)
  line(x1, 25, x1, 75)
  text(str(x1), x1, 15)

  # mapping the value to the second range
  x2 = linmap(x1, min1, max1, min2, max2)
  text(str(round(x2,2)), x2, 285)
  line(x2, 225, x2, 275)
```

### Syntax

```
linmap(value, start1, stop1, start2, stop2, [withinBounds])
```

<table><thead><tr><th width="162">Input</th><th>Description</th></tr></thead><tbody><tr><td>value</td><td>the incoming value to be converted</td></tr><tr><td>start1</td><td>lower bound of the current range</td></tr><tr><td>stop1</td><td>higher bound of the current range</td></tr><tr><td>start2</td><td>lower bound of the newly mapped range</td></tr><tr><td>stop2</td><td>higher bound of the newly mapped range</td></tr><tr><td>withinBounds</td><td>boolean that specifies the behavior of the method if the mapped value is out of the bounds [start2, stop2]</td></tr></tbody></table>

### Description

**Maps** a value from one range to another, such that the **proportions are the same.**&#x20;

For example, number 2.5 is mapped from the range \[0, 10] to number 25 in the range \[0, 100]. Why? Because **in both cases, the value is fourth the distance away from the starting point of the range, and three fourths away from the ending point.**

Mapping 2.5 from the range \[0, 10] to the range \[10, 20] would give 12.5 for the same reason.

mapping 2.5 from the range \[0, 10] to the range \[10, 30] would give 15 for the same reason.

{% hint style="info" %}
Find these documents helpful? Let the people who made them help your child learn to code at [**Strivemath**](https://www.strivemath.com/)<mark style="color:blue;">**!**</mark>

We'd love to hear your Feedback/Comments [here](https://docs.google.com/forms/d/e/1FAIpQLSeqorBAGTya-YBRI-VFjJxtgQtCz3ucGDI96K96sNyuaGuvdw/viewform?usp=sf_link).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://learnpython.strivemath.com/p5-python-web/reference/math/linmap.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
