Category:Evaldraw: Difference between revisions

Content deleted Content added
Torbjoern (talk | contribs)
m →‎Statements: bullets
Torbjoern (talk | contribs)
→‎Arrays: add struct section
 
(One intermediate revision by the same user not shown)
Line 56:
===Arrays===
Arrays that are power of two are wrapped, non power-of-two arrays set index zero if accessed out of bounds.
For example, if we define static xcoords[4]; and try to access xcoords[5] we the returned value is at index 5%4 which is xcoords[1].
 
===Structs===
Structs can be declared and be passed as function parameters.
A struct may doubles, arrays of doubles and other structs.
 
For example struct vec{x,y,z;}; defines a struct with 3 fields.
struct boid_t{ vec pos; vec dir; } defines a struct that contains substructs pos and dir.
 
===Pass by value or pass by ref===
Line 64 ⟶ 72:
There are many built in functions.
The EVAL and RSCRIPT compiler modes support the following 1-param functions:
* ABS - gives the absolute value. Same as fabs in C.
ABS ACOS ASIN ATAN ATN CEIL COS EXP FABS FACT FLOOR INT LOG SGN SIN SQRT TAN UNIT
* ACOS - arcos in radians
And the following two param functions: ATAN2 FADD FMOD LOG MIN MAX POW
* ASIN - arsin in radians
* ATAN - arctan in radians
* ATN - alias for atan
* CEIL - round a value up to nearest integer.
* COS - cosine in radians
* EXP - raise Eulers number to some power. EXP(1) = 2.718281
* FABS - alias for ABS
* FACT - factorial. FACT(5) = 5!
* FLOOR - round a value down to nearest integer.
* INT - different from floor, truncates (removes decimals).
* LOG - returns the natural logarithm of x. LOG(x) = ln(x)
* SGN - returns the sign of a number. -1, 0 or +1
* SIN - sine in radians
* SQRT - square root
* TAN - tan in radians
* UNIT - returns the unit function of x. Returns 0.0 for x<0, 0.5 for x==0 and 1.0 for x>0.
 
And the following two param functions: ATAN2 FADD FMOD LOG MIN MAX POW
* ATAN2(x,y) - gives angle in radians from positive x-axis to some point x,y.
* FADD - eval and rscript compatibility.
* FMOD - alternative to modulus % operator.
* LOG(x,b) - return log of x with base b.
* MIN(a,b) - return smallest
* MAX(a,b) - return largest
* POW(a,b) - raise a to power b
 
There is no concept of include statements or libraries. It is assumed evaldraw programs are small scripts to try out ideas that later will be integrated into a professional programming language such as C.