abs

ceil

constrain

dist

exp

floor

lerp

log

mag

map-range

norm

pow

round

sq

sqrt

abs

Arguments
[n]
Docstring

Calculates the absolute value (magnitude) of a number. The absolute value of a number is always positive. Dynamically casts to an int or float appropriately for Clojure.

Works only inside sketch functions?
No
Original Processing method
abs()
Original p5js method
abs()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/abs -1) = " (q/abs -1)) 10 20)
(q/text (str "(q/abs -0.5) = " (q/abs -0.5)) 10 40)
try example

ceil

Arguments
[n]
Docstring

Calculates the closest int value that is greater than or equal to the value of the parameter. For example, (ceil 9.03) returns the value 10.

Works only inside sketch functions?
No
Original Processing method
ceil()
Original p5js method
ceil()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/ceil 9.03) = " (q/ceil 9.03)) 10 20)
try example

constrain

Arguments
[amt low high]
Docstring

Constrains a value to not exceed a maximum and minimum value.

Works only inside sketch functions?
No
Original Processing method
constrain()
Original p5js method
constrain()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/constrain 4 10 20) = " (q/constrain 4 10 20)) 10 20)
(q/text (str "(q/constrain 4.5 1.5 3.9) = " (q/constrain 4.5 1.5 3.9)) 10 40)
try example

dist

Arguments
[x1 y1 z1 x2 y2 z2][x1 y1 x2 y2]
Docstring

Calculates the distance between two points.

Works only inside sketch functions?
No
Original Processing method
dist()
Original p5js method
dist()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/dist 0 0 3 4) = " (q/dist 0 0 3 4)) 10 20)
(q/text (str "(q/dist 0 0 0 5 5 5) = " (q/dist 0 0 0 5 5 5)) 10 40)
try example

exp

Arguments
[val]
Docstring

Returns Euler's number e (2.71828...) raised to the power of the val parameter.

Works only inside sketch functions?
No
Original Processing method
exp()
Original p5js method
exp()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/exp 2) = " (q/exp 2)) 10 20)
try example

floor

Arguments
[n]
Docstring

Calculates the closest int value that is less than or equal to the value of the parameter. For example, (floor 9.03) returns the value 9.

Works only inside sketch functions?
No
Original Processing method
floor()
Original p5js method
floor()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/floor 9.03) = " (q/floor 9.03)) 10 20)
try example

lerp

Arguments
[start stop amt]
Docstring

Calculates a number between two numbers at a specific increment. The amt parameter is the amount to interpolate between the two values where 0.0 equal to the first point, 0.1 is very near the first point, 0.5 is half-way in between, etc. The lerp function is convenient for creating motion along a straight path and for drawing dotted lines.

Works only inside sketch functions?
No
Original Processing method
lerp()
Original p5js method
lerp()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/lerp 2 5 0.5) = " (q/lerp 2 5 0.5)) 10 20)
try example

log

Arguments
[val]
Docstring

Calculates the natural logarithm (the base-e logarithm) of a number. This function expects the values greater than 0.0.

Works only inside sketch functions?
No
Original Processing method
log()
Original p5js method
log()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/log Math/E) = " (q/log Math/E)) 10 20)
try example

mag

Arguments
[a b c]clj[a b]
Docstring

Calculates the magnitude (or length) of a vector. A vector is a direction in space commonly used in computer graphics and linear algebra. Because it has no start position, the magnitude of a vector can be thought of as the distance from coordinate (0,0) to its (x,y) value. Therefore, mag is a shortcut for writing (dist 0 0 x y).

Works only inside sketch functions?
No
Original Processing method
mag()
Original p5js method
mag()
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    (q/text (str "(q/mag 3 4) = " (q/mag 3 4)) 10 20)
    (q/text (str "(q/mag 3 4 5) = " (q/mag 3 4 5)) 10 40)
clojurescript specific
  • (q/background 255)
    (q/fill 0)
    (q/text (str "(q/mag 3 4) = " (q/mag 3 4)) 10 20)
    try example

map-range

Arguments
[val low1 high1 low2 high2]
Docstring

Re-maps a number from one range to another.

Numbers outside the range are not clamped to 0 and 1, because out-of-range values are often intentional and useful.

Works only inside sketch functions?
No
Original Processing method
map()
Original p5js method
map()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/map-range 2 0 5 10 20) = " (q/map-range 2 0 5 10 20)) 10 20)
try example

norm

Arguments
[val start stop]
Docstring

Normalize a value to exist between 0 and 1 (inclusive).

Works only inside sketch functions?
Yes
Original Processing method
norm()
Original p5js method
norm()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/norm 20 0 50) = " (q/norm 20 0 50)) 10 20)
try example

pow

Arguments
[num exponent]
Docstring

Facilitates exponential expressions. The pow function is an efficient way of multiplying numbers by themselves (or their reciprocal) in large quantities. For example, (pow 3 5) is equivalent to the expression (* 3 3 3 3 3) and (pow 3 -5) is equivalent to (/ 1 (* 3 3 3 3 3)).

Works only inside sketch functions?
No
Original Processing method
pow()
Original p5js method
pow()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/pow 2 10) = " (q/pow 2 10)) 10 20)
try example

round

Arguments
[val]
Docstring

Calculates the integer closest to the value parameter. For example, (round 9.2) returns the value 9.

Works only inside sketch functions?
No
Original Processing method
round()
Original p5js method
round()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/round 9.2) = " (q/round 9.2)) 10 20)
try example

sq

Arguments
[a]
Docstring

Squares a number (multiplies a number by itself). The result is always a positive number, as multiplying two negative numbers always yields a positive result. For example, -1 * -1 = 1.

Works only inside sketch functions?
No
Original Processing method
sq()
Original p5js method
sq()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/sq 5) = " (q/sq 5)) 10 20)
try example

sqrt

Arguments
[a]
Docstring

Calculates the square root of a number. The square root of a number is always positive, even though there may be a valid negative root. The square root s of number a is such that (= a (* s s)). It is the opposite of squaring.

Works only inside sketch functions?
No
Original Processing method
sqrt()
Original p5js method
sqrt()
Example
(q/background 255)
(q/fill 0)
(q/text (str "(q/sqrt 25) = " (q/sqrt 25)) 10 20)
try example