back to index

IntArray

Inheritance

Object -> IntArray

Properties

numElements - - number of used elements 
maxElements - - number of available elements 

Methods

        add            (int _i)                            - add element, i.e. elements[numElements++]
        addEmpty       (int _num)                          - increase numElements by _num
int     alloc          (int _num)                          - discard elements and allocate _num new ones
int     contains       (int _value)                        - return true if the given value exists in this array
        delete         (int _idx)                          - delete element at index _idx
        empty          ()                                  - set numElements to 0
        fill           (int _i)                            - set all elements to _i
        free           ()                                  - discard all elements 
int     get            (int _index)                        - safe-get value at index, silently return 0 if value was not found
int     getAbsMax      ();                                 - return the sign-independent highest value. 0 if array is empty.
float   getAbsMean     ();                                 - return the sign-independent arithmetic mean. 0 if array is empty.
int     getAbsMin      ();                                 - return the sign-independent lowest value. 0 if array is empty. 
int     getMax         ();                                 - return the highest value. 0 if array is empty.
float   getMean        ();                                 - return the arithmetic mean. 0 if array is empty.
int     getMin         ();                                 - return the lowest value. 0 if array is empty.
int     getNumElements ()                                  - return number of used elements
int     getMaxElements ()                                  - return number of available elements
String  getString      ()                                  - convert array to string representation
        identity       (int _num)                          - alloc _num elements and set element[i]=i. Set numElements to maxElements.
int     insert         (int _idx, int _i)                  - insert element at index _idx
int      read8          (Stream _ifs, int _num, int _doff)  - read _num bytes from stream, convert byteorder
int     read16         (Stream _ifs, int _num, int _doff)  - read _num shorts from stream, convert byteorder
int     read32         (Stream _ifs, int _num, int _doff)  - read _num longs from stream, convert byteorder
int     realloc        (int _num)                          - resize array, preserve elements if _num>maxElements
int     rearrange      (IntArray _ia)                      - rearrange elements according to indices in _ia
        reverse        ()                                  - reverse element order
        setNumElements (int _num)                          - set number of used elements
        sortByValue    (IntArray _ia)                      - sort elements and write new element-order to _ia. reallocates _ia.
boolean swap           (int _idxa, _idb)                   - swap elements 
        swapByteOrder  ()                                  - swap byteorder of elements (RGBA <=> ABGR)
        visit          (IntArray _src, int _off, int _num) - create a "view" into another IntArray (no elements copied)
int     visitBytes     (Object _src, int _offBytes, int _numBytes) - create a "view" into another array (no elements copied)
int     write8         (Stream _ofs, int _num, int _soff)  - write _num bytes to stream, convert byteorder
int     write16        (Stream _ofs, int _num, int _soff)  - write _num shorts to stream, convert byteorder
int     write32        (Stream _ofs, int _num, int _soff)  - write _num longs to stream, convert byteorder

Examples

int ia[10];
trace "ia.numElements="+ia.numElements;
trace "ia.maxElements="+ia.maxElements;
loop(10)
  ia.add(rnd(100));
trace "ia.numElements="+ia.numElements;
trace "ia.maxElements="+ia.maxElements;


// ---- 256x256x32 bit rotzoomer ----
int ibuffer[256*256*2];
float deltat=0;

function render() compile {
    int dx;
    int dy;
    int fx;
    int fy;
    int ffx;
    int ffy;
    int i;
    // ---- Calculate the zooming and rotating ----
    dx=sin(deltat)*(550.0+(sin(deltat/3.0)*500.0));
    dy=cos(deltat)*(550.0+(sin(deltat/3.0)*500.0));
    fx=((128+(sin(deltat/4.0)*900.0))<<8)-128*dx-128*dy;
    fy=((128+(cos(deltat/4.0)*300.0))<<8)-128*dy+128*dx;
    i=65536;  // the "tpix" buffer is part of the "buffer"
    loop(256)
	{
	    ffx = fx; ffy = fy;
	    loop(256)
		{
		    fy+=dy;
		    fx+=dx;
		    ibuffer[i++]=ibuffer[(fy&$ff00)|((fx>>8)&$FF)];
		}
	    fx = ffx + dy; fy = ffy - dx;
	}
}

loop(1000)
{
    render();
    deltat+=0.03;
}



back to index