MCPcopy Index your code
hub / github.com/processing/p5.js / calculation

Function calculation

src/math/calculation.js:7–1013  ·  view source on GitHub ↗

* @module Math * @submodule Calculation * @for p5

(p5, fn)

Source from the content-addressed store, hash-verified

5 */
6
7function calculation(p5, fn){
8 /**
9 * Calculates the absolute value of a number.
10 *
11 * A number's absolute value is its distance from zero on the number line.
12 * -5 and 5 are both five units away from zero, so calling `abs(-5)` and
13 * `abs(5)` both return 5. The absolute value of a number is always positive.
14 *
15 * @method abs
16 * @param {Number} n number to compute.
17 * @return {Number} absolute value of given number.
18 *
19 * @example
20 * function setup() {
21 * createCanvas(100, 100);
22 *
23 * describe('A gray square with a vertical black line that divides it in half. A white rectangle gets taller when the user moves the mouse away from the line.');
24 * }
25 *
26 * function draw() {
27 * background(200);
28 *
29 * // Divide the canvas.
30 * line(50, 0, 50, 100);
31 *
32 * // Calculate the mouse's distance from the middle.
33 * let h = abs(mouseX - 50);
34 *
35 * // Draw a rectangle based on the mouse's distance
36 * // from the middle.
37 * rect(0, 100 - h, 100, h);
38 * }
39 */
40 fn.abs = Math.abs;
41
42 /**
43 * Calculates the closest integer value that is greater than or equal to a
44 * number.
45 *
46 * For example, calling `ceil(9.03)` and `ceil(9.97)` both return the value
47 * 10.
48 *
49 * @method ceil
50 * @param {Number} n number to round up.
51 * @return {Integer} rounded up number.
52 *
53 * @example
54 * function setup() {
55 * createCanvas(100, 100);
56 *
57 * background(200);
58 *
59 * // Use RGB color with values from 0 to 1.
60 * colorMode(RGB, 1);
61 *
62 * noStroke();
63 *
64 * // Draw the left rectangle.

Callers 2

calculation.jsFile · 0.85
calculation.jsFile · 0.85

Calls 3

findMaxFunction · 0.85
findMinFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected