Skip to content

Commit 7578459

Browse files
committed
Edit map and add thumbnail
1 parent 4c446c4 commit 7578459

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
/*
1+
/**
22
* @name Map
3-
* @arialabel Red circle grows larger and turns more yellow as the user’s mouse moves right on the screen and does the opposite as the user’s mouse moves left
4-
* @description Use the map() function to take any number and scale it to a
5-
* new number that is more useful for the project that you are working on.
6-
* For example, use the numbers from the mouse position to control the size or color of a shape.
7-
* In this example, the mouse’s x-coordinate (numbers between 0 and 360) are scaled to new numbers
8-
* to define the color and size of a circle.
3+
* @description The
4+
* <a href="https://p5js.org/reference/#/p5/map" target="_blank">map()</a>
5+
* function converts a value from one range to another. In this example, map
6+
* converts the cursor's horizontal position from a range of 0-720 to 0-360.
7+
* The resulting value become the circle's hue. Map also converts the cursor's
8+
* vertical position from a range of 0-400 to 20-300. The resulting value
9+
* becomes the circle's diameter.
910
*/
1011
function setup() {
1112
createCanvas(720, 400);
13+
colorMode(HSB);
1214
noStroke();
15+
textOutput();
1316
}
1417

1518
function draw() {
1619
background(0);
17-
// Scale the mouseX value from 0 to 720 to a range between 0 and 175
18-
let c = map(mouseX, 0, width, 0, 175);
19-
// Scale the mouseX value from 0 to 720 to a range between 40 and 300
20-
let d = map(mouseX, 0, width, 40, 300);
21-
fill(255, c, 0);
22-
ellipse(width/2, height/2, d, d);
20+
21+
// Scale the mouseX value from 0 to 720 to a range between 0 and 360
22+
let circleHue = map(mouseX, 0, width, 0, 360);
23+
24+
// Scale the mouseY value from 0 to 400 to a range between 20 and 300
25+
let diameter = map(mouseY, 0, height, 20, 300);
26+
27+
fill(circleHue, 80, 90);
28+
circle(width / 2, height / 2, diameter);
2329
}
14.4 KB
Loading

0 commit comments

Comments
 (0)