EACoder Help Center
|
EACoder Operator and Command List v0.1
The following tables list and describe the php
functions and operators which are available to users of EACoder for use in their EACoder
scripts, as well as EACoder's special variables. In addition to a brief description, each entry also includes a
syntax example in order to provide you with the ability to dive right into the
function without further delay.
This is a prototype
document and may not be complete in the information it relays about the
functions available to users of EACoder. It is subject to revision at any
time.
EACoder special variables
$x | EACoder-supplied horizontal coordinate. | $red = $x * $y; |
$y | EACoder-supplied vertical coordinate. | $red = $x * $y; |
$red | Output variable for red channel. | $red = $x * $y; |
$green | Output variable for green channel. | $green = $x * $y; |
$blue | Output variable for blue channel. | $blue = $x * $y; |
$alpha | Output variable for alpha channel (transparency). Optional | $alpha = $x; |
The basic mathematical operators + - * / (plus minus times divide) work as you would expect, including the usual order of operations. By the way, % is actually the modulo operator in PHP - don't try to use it for division.
PHP's basic assignment operator is a single = symbol (note that == and === have entirely different meanings in PHP). In addition to being used on its own, = may be appended (tacked on) to a number of operators. This is a shorthand borrowed from the C programming language, and it works like this:
$x += 1; is equivalent to
$x = $x + 1;
The assignment operators are:
| = | += | -= | *= | /= | %= | ^= | |= | &= | <<= | >>= | .= |
Advanced Mathematical Commands
pi() | Returns pi. | $x = pi(); |
abs() | Absolute. Discards sign, so negative becomes positive and positive stays positive. | $x = abs($y); |
acos() | Inverse cosine. | $x = acos($y); |
acosh() | Inverse hyperbolic cosine. | $x = acosh($y); |
asin() | Inverse sine. | $x = asin($y); |
asinh() | Inverse hyperbolic sine. | $x = asinh($y); |
atan() | Inverse tangent. | $x = atan($a); |
atan2() | Quadrant-aware inverse tangent (takes two arguments). | $t = atan2($y,$x); |
atanh() | Inverse hyperbolic tangent. | $x = atanh($y); |
cos() | Cosine. | $x = cos($y); |
cosh() | Hyperbolic cosine. | $x = cosh($y); |
exp() | Returns e raised to a power. | $x = exp($y); |
log() | Natural logarithm. | $x = log($y); |
log10() | Base 10 logarithm. | $x = log10($y); |
pow() | Power function | $z = pow($x,$y); |
sin() | Sine. | $x = sin($y); |
sinh() | Hyperbolic sine. | $x = sinh($y); |
sqrt() | Square root. | $x = sqrt($y); |
tan() | Tangent. | $x = tan($y); |
tanh() | Hyperbolic tangent. | $x = tanh($y); |
bindec() | Converts binary to decimal. | $x = bindec($y); |
decbin() | Converts decimal to binary. | $x = decbin($y); |
dechex() | Converts decimal to hexadecimal. | $x = dechex($y); |
decoct() | Converts decimal to octal. | $x = decoct($y); |
deg2rad() | Converts degrees to radians . | $x = deg2rad($y); |
hexdec() | Converts hexadecimal to decimal. | $x = hexdec($y); |
octdec() | Converts octal to decimal. | $x = octdec($y); |
rad2deg() | Converts radians to degrees. | $x = rad2deg($y); |
rand() | Returns a pseudo-random number between $min and $max | $x = rand($min, $max); |
srand() | Seeds the random number generator. | srand($x); |
getrandmax() | Returns the maximum value of rand(). | $x = getrandmax(); |
floor() | Round down. | $x = floor(2.543); |
ceil() | Round up. | $x = ceil(2.543); |
fmod() | Floating-point modulo. | $x = fmod($y, $z); |
min() | This command returns the smallest of the values which are given as parameters. | $x=min($number1, $number2, $number3); |
max() | This command returns the highest of the values which are given as parameters. | $x=max($number1, $number2, $number3); |
| && | Logical AND. | if ($x==1 && $y==2) |
|| | Logical OR. | if ($x==10 || $y==45) |
! | Logical NOT. | if (!$x==6) |
and | Logical AND. | if ($x==5 and $y==7) |
or | Logical OR. | if ($x==5 or $y==3) |
xor | Logical XOR (exclusive OR). | if ($x==4 xor $y==1) |
| & | Bitwise AND | $x = $a & $b; |
| | Bitwise OR. | $x = $a | $b; |
^ | Bitwise XOR (exclusive OR). | $x = $a ^ $b; |
~ | Bitwise NOT | $x = ~$a; |
<< | Bitshift left | $x = $a << $b; |
>> | Bitshift right | $x = $a >> $b; |
== | Equals. | if ($x==1) |
=== | Equivalence. Equal and of same data type. | if ($x===1) |
< | Less than. | if ($x<1) |
> | Greater than. | if ($x>1) |
<= | Less than or equal. | if ($x<=1) |
>= | Greater than or equal. | if ($x>=1) |
if | The basic conditional. | if ($x==1) { $y=10; } |
elseif | Conditional else. | if ($x==1) { $y=10; } elseif ($x>1) { $y=20; } |
else | Else. | if ($x==1) { $y=10; } else { $y=30; } |
while | Execute codeblock whilever condition is TRUE. | while ($x < 20) { $x++; } |
do-while | Same as while, but condition is checked at the end of the codeblock instead of the start. | do { $x++; } while ($x < 20); |
for | Execute codeblock while condition is TRUE, performing some change after each iteration. Typically used to execute a codeblock a predefined number of times. | for ($counter=1; $counter<=20; $counter++) { $x++; } |
foreach | Perform the same actions on every variable in an array. | foreach ($avar as $i) { $r = $r * $i - $i; } |
break | Break out of a loop early. | while ($x < 20) { $x++; if ($x == 10) { break; } } |
continue | Skip one iteration of a loop. | while ($x < 20) { $x++; if ($x == 10) { continue; } } |
Array Functions
array() | Store values in an array. | $arr = array(1,2,3,4,5); |
array_count_values() | Count all values in an array. | $arr2 = array_count_values($arr1); |
array_product() | Return the product of all values in an array. | $product = array_product ($arr1); |
array_rand() | Pick random entries from an array. | $r = array_rand($arr1);
or $r = array_rand($arr1, 3); |
array_sum() | Return the sum of all values in an array. | $r = array_sum($arr1); |
in_array() | Searches for a specific value in an array. | $is_there = in_array($value, $array); |
current() | Returns the current array value. | $current_value = current($arr1); |
pos() | Another name for current() | $current_value = pos($arr1); |
sort() | Sort an array. | sort ($arr1); |
next() | Return the next value in an array. Moves the internal array pointer. | $next_value = next($array); |
count() | Returns the number of elements in an array. | $len = count($arr1); |
end() | Returns the last value in an array. Moves the internal array pointer. | $last_value = end($arr1); |
Miscellaneous PHP
function | Structure for user-created functions. | function sum($n) { return $n/2 * ($n + 1); } |
++ | Short-hand for +=1. Commonly used with for | $x++; |
-- | Short-hand for -=1. | $x--; |
Notes
|