Skip to content

Commit 78fdb0e

Browse files
committed
Merge pull request #235 from ndeleon/master
Updated the example for the map() function
2 parents 94d371a + 8b1fecd commit 78fdb0e

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

content/api_en/print.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The <b>print()</b> function writes to the console area, the black rectangle at t
4242
<br />
4343
Using <b>print()</b> on an object will output <b>null</b>, a memory location that may look like "@10be08," or the result of the <b>toString()</b> method from the object that's being printed. Advanced users who want more useful output when calling <b>print()</b> on their own classes can add a <b>toString()</b> method to the class that returns a String.<br />
4444
<br />
45-
Note that the console is relatively slow. It works well for occasional messages, but does not support high-speed, real-time output (such as at 60 frames per second).
45+
Note that the console is relatively slow. It works well for occasional messages, but does not support high-speed, real-time output (such as at 60 frames per second). It should also be noted, that a print() within a for loop can sometimes lock up the program, and cause the sketch to freeze.
4646
]]></description>
4747

4848
</root>

content/api_en/println.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The <b>println()</b> function writes to the console area, the black rectangle at
4343
<br />
4444
Before Processing 2.1, <b>println()</b> was used to write array data to the console. Now, use <b>printArray()</b> to write array data to the console.<br />
4545
<br />
46-
Note that the console is relatively slow. It works well for occasional messages, but does not support high-speed, real-time output (such as at 60 frames per second).
46+
Note that the console is relatively slow. It works well for occasional messages, but does not support high-speed, real-time output (such as at 60 frames per second). It should also be noted, that a println() within a for loop can sometimes lock up the program, and cause the sketch to freeze.
4747
]]></description>
4848

4949
</root>
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, 640) and we are scaling that to another
10+
* range (40 to 300 for size, and 0 to 175 for color).
11+
*
12+
*/
13+
void setup() {
14+
size(640, 360);
15+
noStroke();
16+
}
17+
18+
void draw() {
19+
background(0);
20+
// mouseX has a min of 0 and a max of 640 (the width of the window)
21+
// here we are scaling that variable from 0 to 640 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, 300);
25+
fill(255, c, 0);
26+
ellipse(width/2, height/2, d, d);
27+
}

0 commit comments

Comments
 (0)