リファレンス › Mathematics — 61 個のコマンド
+
入力: number | number
出力: 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
-
入力: number | number
出力: number
Subtracts two numbers or numerical results of other primitives. Similar to difference
print 5 - 4
1
*
入力: number | number
出力: number
Multiplies two numbers or numerical results of other primitives. Similar to product
print 6 * 3
18
/
入力: number | number
出力: number
Divides two numbers or numerical results of other primitives. Similar to quotient
print 12 / 4
3
^
入力: number | number
出力: number
Returns the first number to the power of the second number. Similar to power
show 5 ^ 3
125
%
入力: number | number
出力: number
Returns the remainder from dividing the first number by the second number. Similar to remainder
show 10 % 4
2
abs
入力: number
出力: absolute-number
Returns the absolute (non-negative) value of the input provided.
pr abs -54
54
arccos
入力: number
出力: number
Returns the inverse cosine of the provided number. The number must be between -1 and 1.
show arccos 0.2
arcsin
入力: number
出力: number
Returns the inverse sine of the provided number. The number must be between -1 and 1.
show arcsin 4
arctan
入力: number
出力: number
Returns the arctangent (inverse) of number in degrees.
print arctan 50
88.854199
arctan2
入力: x y
出力: 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
入力: number (number) | floor (number) | ceiling (number)
出力: 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
入力: input (number)
出力: output (output)
Returns the cosine of the input. See sin
show cos 120
-0.50000077735
decrement
別名: dec
入力: word
出力: 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
入力: number1 (number) | number2 (number)
出力: number
Difference outputs the result of subtracting number 2 from number 1.
show difference 5 1
4
e
入力: none
出力: number
Returns the constant e, which is 2.7182818284590452353
show e
epsilon
入力: none
出力: 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
別名: frac
入力: number
出力: 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
別名: int
入力: number
出力: number
Returns the integer value (rounded down) of the provided number.
show integer 23.34
23
intquotient
入力: number1 (number) | number2 (number)
出力: number
Returns the integer of the quotient (division) of the two provided input numbers. See quotient, remainder
show intquotient 22 7
3
ln
入力: number
出力: number
Returns the natural logarithm of the given input
show ln 100
log
入力: number
出力: number
Returns the log of the given number.
show log 5
0.698970004336
max
入力: number | number
出力: number
Returns the greater of the two provided numbers. See min
show max 4 6
6
min
入力: number | number
出力: number
Returns the lesser of the two provided numbers. See max
show min 4 5
4
mod
入力: numerator (number) | denominator (number)
出力: 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
入力: number
出力: 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
入力: none
出力: list
Returns the current perlin noise parameters. See setperlin, perlinnoise
show perlin
perlinnoise
入力: [x] or [x y] or [x y z] (list)
出力: 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
入力: none
出力: number
Returns 3.141592653589793
show pi
3.141592653589793
power
入力: number | number
出力: number
Returns the power of the second number to the first number. Similar to ^.
show power 5 5
125
product
入力: number1 (number) | number2 (number)
出力: number
Returns the product of (multiplies) its two inputs, similar to the * operator.
show product 4 5
20
quotient
別名: quo
入力: number1 (number) | number2 (number)
出力: 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
入力: number
出力: number
Outputs the inverse cosine of its input in radians.
show radarccos 0.5
0.87758256189
radarcsin
入力: number
出力: number
Outputs the inverse sine of its input in radians.
show radarcsin 0.5
0.479425538604
radarctan
入力: number
出力: number
Outputs the inverse tangent of its input in radians.
show radarctan 0.5
0.463647609001
radcos
入力: number
出力: number
Outputs the cosine of the input in radians.
show radcos 0.5
radsin
入力: number
出力: number
Outputs the sine of the input in radians.
show radsin 0.5
radtan
入力: number
出力: number
Outputs the tangent of the input in radians.
show radtan 0.5
random
別名: rd
入力: maximum (number) OR [num] OR [num1 num2] OR [num1 num2 divisor]
出力: 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
別名: randbool
入力: none
出力: boolean
Randomly returns TRUE or FALSE.
show randomboolean
remainder
別名: re
入力: numerator (number) | denominator (number)
出力: 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
入力: number
出力: 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
入力: [from | to | count] (list)
出力: 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
入力: number
出力: 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
入力: weight scaling iterations seed
出力: none
Sets the parameters used by perlinnoise.
setperlin 5 10 2 7
sign
別名: sgn
入力: number
出力: number
Returns 1 if given number is positive, 0 if 0, and -1 if negative.
show sign 23
1
sin
入力: degrees
出力: sine of degrees
Returns the sine of degrees.
print sin 90
sqrt
入力: number
出力: number
Returns the square root of the provided number.
show sqrt 16
4
sum
入力: number1 (number) | number2 (number)
出力: result (number)
Sums (adds) the two provided numbers.
show sum 2 2
4
tan
入力: number
出力: number
Returns the tangent of the supplied number. See arctan
print tan 5
0.087489
truncate
入力: number | decimalplaces (number)
出力: number
Returns the input rounded to the specified number of decimal places.
print truncate 10.4325 2
10.43
vectoradd
入力: vector (list) | vector (list)
出力: list
Add two vectors giving a new vector.
vectoradd [0 1 0] [1 0 1]
[1 1 1]
vectorcross
入力: vector (list) | vector (list)
出力: list
Returns vector perpendicular to the two provided vectors.
show vectorcross [0 .2 0] [0 0.5 0.5]
[0.1 0 0]
vectordot
入力: vector (list) | vector (list)
出力: number
Returns the "dot" product of two vectors.
show vectordot [0 0.12 0.12] [0.5 0 0.5]
0.06
vectornormal
入力: vector (list)
出力: list
Returns a "normal" vector of length 1.
show vectornormal [20 20 20]
[0.5773502691896257 0.5773502691896257 0.5773502691896257]
vectormultiply
入力: vector (list) | amount (number)
出力: list
Multiply vector by given amount.
show vectormultiply [0.5 0.5 0.5] 2
[1 1 1]
vectorsub
入力: vector1 (list) | vector2 (list)
出力: list
Subtract vector1 from vector2, giving a new vector.
show vectorsub [0 1 0] [1 0 1]
[1 -1 1]
diff
入力: number | number
出力: number
Short form of difference. Subtracts the second number from the first.
print diff 10 3 ; prints 7
int
入力: number
出力: 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
入力: list
出力: number
Returns the length (magnitude) of a 3D vector represented as a list [x y z].
print vectorlength [3 4 0] ; prints 5
bit
入力: "mode a b
出力: 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