Unit


Used in /tutorials/paint

#Info

Units are not really a class, but more its own language. It's very similar to MoLang. It's always represented as a string, and is evaluated on client side while rendering, rather than when code is ran.
  • Most basic unit is plain number, such as '1' or '4.5'.
  • You can use variables with a $, like '$example'.
  • Each function requires name parenthesis and comma separated arguments e.g. 'min(PI, $example)'.
  • You can combine as many as you want, e.g. 'min(PI, 10 + $example)'.
  • You can do pretty complex infix, e.g. 'atan2($MY, $MX) - HALF_PI - HALF_PI / 2'.

#Constants


#true

Boolean true value, equal to 1.0

#false

Boolean false value, equal to 0.0

#PI

Number equal to 3.14159265358979323846

#HALF_PI

Number equal to 1.57079632679

#TWO_PI

Number equal to 6.28318530718

#E

Number equal to 2.7182818284590452354

#Variables


#$SW

Screen width
(legacy: $screenW)

#$SH

Screen height
(legacy: $screenH)

#$D

Render tick delta
(legacy: $delta)

#$MX

Mouse X position
(legacy: $mouseX)

#$MY

Mouse Y position
(legacy: $mouseY)

#Operations


#cond ? a : b

Same as if(statement: Unit, trueUnit: Unit, falseUnit: Unit).

#-a

Negate

#a + b

Add

#a - b

Subtract

#a * b

Multiply

#a / b

Divide

#a % b

Modulo

#a ** b

Power

#a & b

Bitwise AND

#a | b

Bitwise OR

#a ^ b

Bitwise/Boolean XOR

#~a

Bitwise NOT

#!a

Boolean NOT

#a << b

Shift Left

#a >> b

Shift Right

#a == b

Equals

#a != b

Not Equals

#a > b

Greater Than

#a < b

Less Than

#a >= b

Greater or Equal Than

#a <= b

Less or Equal Than

#Functions


#random(): Unit

Random number between 0.0 and 1.0.

#time(): Unit

Current time in seconds (includes milliseconds).

#roundTime(): Unit

Current time in seconds (rounded to nearest second).

#min(a: Unit, b: Unit): Unit

Smallest of two Units.

#max(a: Unit, b: Unit): Unit

Largest of two Units.

#pow(a: Unit, b: Unit): Unit

a to the power of b.

#abs(a: Unit): Unit

Absolute value of a (always positive).

#sin(a: Unit): Unit

Math.sin(a)

#cos(a: Unit): Unit

Math.cos(a)

#tan(a: Unit): Unit

Math.tan(a)

#atan(a: Unit): Unit

Math.atan(a)

#atan2(y: Unit, x: Unit): Unit

Math.atan2(y, x)

#deg(a: Unit): Unit

Converts radians to degrees.

#rad(a: Unit): Unit

Converts degrees to radians.

#log(a: Unit): Unit

Logarithm of a.

#log10(a: Unit): Unit

Logarithm base 10 of a.

#log1p(a: Unit): Unit

Returns the natural logarithm of the sum of a and 1.

#sqrt(a: Unit): Unit

Square root of a.

#sq(a: Unit): Unit

Square of a.

#floor(a: Unit): Unit

Round a down to nearest integer.

#ceil(a: Unit): Unit

Round a up to nearest integer.

#if(statement: Unit, trueUnit: Unit, falseUnit: Unit): Unit

Returns trueUnit if statement is not equal to 0.0, otherwise falseUnit.