Skip to content

Commit ae753b8

Browse files
committed
Create Map.pde
1 parent c2fb34e commit ae753b8

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

  • content/examples/Basics/Math/Map
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* map()
3+
*
4+
* Using the map() function allows you to take any number,
5+
* and scale it to a number that is more useful to the project
6+
* that you are working on. Say you want to map mouse movement
7+
* to the size or color (as seen above) of an object.
8+
* In this example, we are taking the mouse’s x position (which can
9+
* be between 0 and the width, 700) and we are scaling that to another
10+
* range (40 to 440 for size, and 0 to 175 for color).
11+
*
12+
*/
13+
void setup() {
14+
size(700, 500);
15+
noStroke();
16+
}
17+
18+
void draw() {
19+
background(0);
20+
// mouseX has a min of 0 and a max of 700 (the width of the window)
21+
// here we are scaling that variable from 0 to 700 to a number between 0 and 255
22+
float c = map(mouseX, 0, width, 0, 175);
23+
// here we are scaling that same variable to a range between 40 and 440
24+
float d = map(mouseX, 0, width, 40, 440);
25+
fill(255, c, 0);
26+
ellipse(width/2, height/2, d, d);
27+
}

0 commit comments

Comments
 (0)