Undolibrary MatrixArray: an extension of the Array class

di Actionscript 3.0, con lo scopo di semplificare la manipolazione di Array lineari usati come matrice n x m . MatrixArray is an extension of the class Array of Actionscript 3.0, with the aim to simplify the manipulation of Array used as a linear n x m matrix. This class is part of the library Undolibrary (in the package undolibrary.utils.MatrixArray ) that you can freely download function via any Google code SVN client (Subversion) to:
svn checkout http://undolibrary.googlecode.com/svn/trunk/
Alternatively you can download the single file MatrixArray.as . An example of the use of linear matrix was given in Actionscript 3.0 for beginners: lesson # 2 where we saw one of his simple use in the production of the classic Tic Tac Toe game. ), proprio come una scacchiera. An array of this type is comparable to a rectangular area ( w x h ), just like a chessboard. With this class you can treat an array of this type just like a grid with its x and y coordinates. The MatrixArray I've used, for example, in the development of all the logic editor Emotions Icons for Skype: Skypemote .

Methods

aggiungendo una serie di utili metodi per gestire e manipolare matrici n x m . The class MatrixArray therefore extends the normal class Array by adding a number of useful methods to manage and manipulate n x m matrix. To create a matrix n x m is sufficient to use:

1
2
3
4
5
/ / Importanzione class - if you downloaded the entire library Undolibrary
/ / Alternatively you can download only the file and use it alone MatrixArray.as
utils . MatrixArray ; undolibrary imports. utils. MatrixArray;
/ /
MatrixArray = new MatrixArray ( 10 , 10 ) ; var but: MatrixArray = new MatrixArray (10, 10);

Created 10 × 10 matrix, as in the previous example, we can manipulate it with methods that help make our work very fast and simple. In fact, the 10 × 10 matrix is ​​nothing more than a simple linear array of 100 elements!

clip ()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/ **
* Restitusice a rectangular portion of the matrix in the form MatrixArray
*
* @ Param (uint) left x-coordinate of the cut
* @ Param (uint) sy y coordinates of the cut
* @ Param (uint) cw horizontal dimension of the cut
* @ Param (uint) ch vertical dimension of the cut
* @ Result (MatrixArray) A new matrix x cw ch
*
* /
uint , sy : uint , cw : uint , ch : uint ) : MatrixArray clips (left: uint , sy: uint , cw: uint , ch: uint ): MatrixArray

/ / Example
/ / Create a new 2.2 MatrixArray coordinates and width and height 5
MatrixArray = ma . clip ( 2 , 2 , 5 , 5 ) ; var nma: MatrixArray = ma. clips (2, 2, 5, 5);

fill ()

1
2
3
4
5
6
/ **
* Fill the array with a given value
*
* @ Param (any) value to be included in the matrix
* /
) ; fill (v: *);

paintChar ()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/ **
* Fills the matrix with (only) taken from a character string
* Length equal to the size of the matrix
*
* @ Param (string) string v with the number of characters to be mapped
* @ Result (boolean) true ok, false error: Incorrect string length
*
* /
string ) paintChar (v: string)

/ / Example

MatrixArray = new MatrixArray ( 10 , 5 ) ; var but: MatrixArray = new MatrixArray (10, 5);
but. paintChar (
'**********' +
'**##**##**' +
'**********' +
'**#####**' +
'**********'
);

flipH (), flipV ()

1
2
3
4
5
6
/ **
* Performs a reflection orizziontale (flipH) or
* Vertical (flipV) directly on the matrix
* /
void flipH (): void
void flipV (): void

move ()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/ **
* Move the contents of the array (making a shift) in the four
* The direction of a predetermined offeset
* /
int , oy : int ) : void move (x: int , y: int ): void
/ /

MatrixArray = new MatrixArray ( 10 , 5 ) ; var but: MatrixArray = new MatrixArray (10, 5);
but. paintChar (
'**********' +
'**##**##**' +
'**********' +
'**#####**' +
'**********'
);
2 , 4 ) ; but. move (2, 4);

/ / Output
## **** ** # # # #
**********
**** #####
**********
**********

peek ()

1
2
3
4
/ **
* Returns the contents of the array at coordinates x, y
* /
: uint , y : uint ) :* peek (x: uint , y: uint ): *

poke ()

1
2
3
4
/ **
* Sets the content of the matrix to the coordinates x, y
* /
: uint , y : uint ) : void poke (x: uint , y: uint ): void

getString ()

1
2
3
4
/ **
Often used for debugging * returns the array as a string nxm
* /
String getString (): String

There are no comments for this post

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL