Reference › Mathematics — 61 commands


+

mathematics

Input: number | number
Output: number

Adds two numbers or numerical results of other primitives. Can be placed before or between the two items to be added. Note that expressions in turtleSpaces are parsed right to left, in a collapsing fashion, using BEDMAS ordering. As such you must use parentheses to ensure the correct order of operations. Similar to sum

print 3 + 4  print + 3 4
make "container xpos + ypos

-

mathematics

Input: number | number
Output: number

Subtracts two numbers or numerical results of other primitives. Similar to difference

print 5 - 4
1

*

mathematics

Input: number | number
Output: number

Multiplies two numbers or numerical results of other primitives. Similar to product

print 6 * 3
18

/

mathematics

Input: number | number
Output: number

Divides two numbers or numerical results of other primitives. Similar to quotient

print 12 / 4
3

^

mathematics

Input: number | number
Output: number

Returns the first number to the power of the second number. Similar to power

show 5 ^ 3
125

%

mathematics

Input: number | number
Output: number

Returns the remainder from dividing the first number by the second number. Similar to remainder

show 10 % 4
2

abs

mathematics

Input: number
Output: absolute-number

Returns the absolute (non-negative) value of the input provided.

pr abs -54
54

arccos

mathematics

Input: number
Output: number

Returns the inverse cosine of the provided number. The number must be between -1 and 1.

show arccos 0.2

arcsin

mathematics

Input: number
Output: number

Returns the inverse sine of the provided number. The number must be between -1 and 1.

show arcsin 4

arctan

mathematics

Input: number
Output: number

Returns the arctangent (inverse) of number in degrees.

print arctan 50
88.854199

arctan2

mathematics

Input: x y
Output: angle

Measures the counterclockwise angle θ, in radians, between the positive x-axis and the point (x, y). If turtle is at 0,0 if you set the heading to the output of arctan2 the turtle will point towards the given co-ordinates.

setheading arctan2 10 10

clamp

mathematics

Input: number (number) | floor (number) | ceiling (number)
Output: number

clamp takes the inputted number, and if it is lower than the floor, or higher than the ceiling, it returns the floor or the ceiling respectively. If the first number is provided in the form of a list, the result 'wraps' around the floor or ceiling values as appropriate.

print clamp 10 5 20
10
print clamp 1 5 20
5
print clamp 30 5 20
20
print clamp [25] 10 20
15

cos

mathematics

Input: input (number)
Output: output (output)

Returns the cosine of the input. See sin

show cos 120
-0.50000077735

decrement

Also: dec

mathematics

Input: word
Output: none

Decreases the value of the specified container (variable) by one. Note that the container (variable) specified by dec begins with a quote (") not a colon. This is so that you can pass dec a container specified inside another container. See inc

make "counter 10
dec "counter
print :counter
9
will decrement the container named counter by one.
make "fred 5
make "counter "fred
dec :counter
print :fred
4
will decrement the container specified by :counter ("fred) by one.

difference

mathematics

Input: number1 (number) | number2 (number)
Output: number

Difference outputs the result of subtracting number 2 from number 1.

show difference 5 1
4

e

mathematics

Input: none
Output: number

Returns the constant e, which is 2.7182818284590452353

show e

epsilon

mathematics

Input: none
Output: number

Contains the minimum value that two numbers may differ to still be considered to be equal by ~ or approximatep. See setepsilon

show epsilon

fraction

Also: frac

mathematics

Input: number
Output: number

Returns the fractional part of a number. Similar to mod X 1 or X - int X. See mod, int

show frac 3.14
0.14

integer

Also: int

mathematics

Input: number
Output: number

Returns the integer value (rounded down) of the provided number.

show integer 23.34
23

intquotient

mathematics

Input: number1 (number) | number2 (number)
Output: number

Returns the integer of the quotient (division) of the two provided input numbers. See quotient, remainder

show intquotient 22 7
3

ln

mathematics

Input: number
Output: number

Returns the natural logarithm of the given input

show ln 100

log

mathematics

Input: number
Output: number

Returns the log of the given number.

show log 5
0.698970004336

max

mathematics

Input: number | number
Output: number

Returns the greater of the two provided numbers. See min

show max 4 6
6

min

mathematics

Input: number | number
Output: number

Returns the lesser of the two provided numbers. See max

show min 4 5
4

mod

mathematics

Input: numerator (number) | denominator (number)
Output: number

Returns the floating-point remainder of the division of the supplied numerator by the denominator, as opposed the remainder primitive, which takes and returns integer (whole) values. See remainder

show mod 22 6.5
2.5

negative

mathematics

Input: number
Output: number

Returns the negative of the provided number. You can also negate containers or advisor returns by prefixing them with -, eg -:container or -advisor. See abs

show negative 10
-10
show negative -20
20

perlin

mathematics

Input: none
Output: list

Returns the current perlin noise parameters. See setperlin, perlinnoise

show perlin

perlinnoise

mathematics

Input: [x] or [x y] or [x y z] (list)
Output: number

Returns perlin noise values based on the co-ordinates provided, the perlin noise parameters and the current turtle bounds. See setbounds, setperlin, perlin.

show perlinnoise {xpos ypos}

pi

mathematics

Input: none
Output: number

Returns 3.141592653589793

show pi
3.141592653589793

power

mathematics

Input: number | number
Output: number

Returns the power of the second number to the first number. Similar to ^.

show power 5 5
125

product

mathematics

Input: number1 (number) | number2 (number)
Output: number

Returns the product of (multiplies) its two inputs, similar to the * operator.

show product 4 5
20

quotient

Also: quo

mathematics

Input: number1 (number) | number2 (number)
Output: number

Returns the first number divided by the second number, similar to using the / operator. See intquotient, remainder

show quotient 22 7
3.142857142857143

radarccos

mathematics

Input: number
Output: number

Outputs the inverse cosine of its input in radians.

show radarccos 0.5
0.87758256189

radarcsin

mathematics

Input: number
Output: number

Outputs the inverse sine of its input in radians.

show radarcsin 0.5
0.479425538604

radarctan

mathematics

Input: number
Output: number

Outputs the inverse tangent of its input in radians.

show radarctan 0.5
0.463647609001

radcos

mathematics

Input: number
Output: number

Outputs the cosine of the input in radians.

show radcos 0.5

radsin

mathematics

Input: number
Output: number

Outputs the sine of the input in radians.

show radsin 0.5

radtan

mathematics

Input: number
Output: number

Outputs the tangent of the input in radians.

show radtan 0.5

random

Also: rd

mathematics

Input: maximum (number) OR [num] OR [num1 num2] OR [num1 num2 divisor]
Output: number

If a single number is provided, random returns a random integer (whole number) between 0 and the specified maximum, but not including that maximum. So, for example, random 2 returns one of two numbers, 0 or 1. random 8 returns one of 8 numbers, between zero and 7. If a single number is provided as a list (eg [10]) random returns a value between 1 and that number, inclusive. If two list items are provided, random picks a number between and including num1 and num2. If a third value is provided, the returned random number is divisible by that number. Note also that random 0 returns a fraction between 0 and 1. random does a lot of stuff!

show random 16
3
show 1 + random 15
4
show (random 15) + 1
4

randomboolean

Also: randbool

mathematics

Input: none
Output: boolean

Randomly returns TRUE or FALSE.

show randomboolean

remainder

Also: re

mathematics

Input: numerator (number) | denominator (number)
Output: integer (number)

Returns the integer remainder of the division of the numerator by the denominator. The numerator and denominator are converted to integers if they are not provided as integers. For floating-point calculations, use mod

show remainder 22 7
1

round

mathematics

Input: number
Output: number

Takes a number and returns it rounded to the nearest whole number, up or down (whichever is closer).

print round 4.6
5
print round 1.2
1

sequence

mathematics

Input: [from | to | count] (list)
Output: list (list)

Similar to range but outputs a list of numbers starting with the first parameter, then takes a number of equally-spaced steps specified by the third parameter to reach the number given in the second parameter. See range

show sequence [1 10 6]
[1 2.5 4 5.5 7 8.5 10]

setepsilon

mathematics

Input: number
Output: none

Sets the minimum value that two numbers may differ to still be considered to be equal by ~ or approximatep. See epsilon

setepsilon 5

setperlin

mathematics

Input: weight scaling iterations seed
Output: none

Sets the parameters used by perlinnoise.

setperlin 5 10 2 7

sign

Also: sgn

mathematics

Input: number
Output: number

Returns 1 if given number is positive, 0 if 0, and -1 if negative.

show sign 23
1

sin

mathematics

Input: degrees
Output: sine of degrees

Returns the sine of degrees.

print sin 90

sqrt

mathematics

Input: number
Output: number

Returns the square root of the provided number.

show sqrt 16
4

sum

mathematics

Input: number1 (number) | number2 (number)
Output: result (number)

Sums (adds) the two provided numbers.

show sum 2 2
4

tan

mathematics

Input: number
Output: number

Returns the tangent of the supplied number. See arctan

print tan 5
0.087489

truncate

mathematics

Input: number | decimalplaces (number)
Output: number

Returns the input rounded to the specified number of decimal places.

print truncate 10.4325 2
10.43

vectoradd

mathematics

Input: vector (list) | vector (list)
Output: list

Add two vectors giving a new vector.

vectoradd [0 1 0] [1 0 1]
[1 1 1]

vectorcross

mathematics

Input: vector (list) | vector (list)
Output: list

Returns vector perpendicular to the two provided vectors.

show vectorcross [0 .2 0] [0 0.5 0.5]
[0.1 0 0]

vectordot

mathematics

Input: vector (list) | vector (list)
Output: number

Returns the "dot" product of two vectors.

show vectordot [0 0.12 0.12] [0.5 0 0.5]
0.06

vectornormal

mathematics

Input: vector (list)
Output: list

Returns a "normal" vector of length 1.

show vectornormal [20 20 20]
[0.5773502691896257 0.5773502691896257 0.5773502691896257]

vectormultiply

mathematics

Input: vector (list) | amount (number)
Output: list

Multiply vector by given amount.

show vectormultiply [0.5 0.5 0.5] 2
[1 1 1]

vectorsub

mathematics

Input: vector1 (list) | vector2 (list)
Output: list

Subtract vector1 from vector2, giving a new vector.

show vectorsub [0 1 0] [1 0 1]
[1 -1 1]

diff

mathematics

Input: number | number
Output: number

Short form of difference. Subtracts the second number from the first.

print diff 10 3 ; prints 7

int

mathematics

Input: number
Output: number

Short form of integer. Returns the integer part of a number by truncating decimal places.

print int 3.7 ; prints 3
print int -3.7 ; prints -3

vectorlength

mathematics

Input: list
Output: number

Returns the length (magnitude) of a 3D vector represented as a list [x y z].

print vectorlength [3 4 0] ; prints 5

bit

mathematics

Input: "mode a b
Output: number

Performs a bitwise logical operation on integers a and b. The mode parameter specifies the operation: "and" performs bitwise AND, "or" performs bitwise OR, "xor" performs bitwise XOR (exclusive or), "left" shifts a left by b bits, "right" shifts a right by b bits, and "not" clears the bits in a that are set in b (bit clear / AND NOT).

show bit "or 128 1
129
show bit "and 255 15
15
show bit "xor 170 85
255
show bit "left 1 4
16
show bit "right 16 2
4
show bit "not 255 15
240