NewPolygon
The NewPolygon function creates and returns a new CPolygon object. This function is a global form of the CPolygon:new method.
P = NewPolygon() P = NewPolygon( CPolygonOld ) P = NewPolygon( arrayX, arrayY ) where The first form, with no arguments, creates a default CPolygon object with default properties. CPolygonOld is an existing CPolygon object. This form creates a new CPolygon object initialized to the properties of CPolygonOld. arrayX, arrayY are two lua arrays containing, respectively, the x values and y values to be used for the polygon points. P is a new CPolygon object. |
The following script illustrates using various forms of NewPolygon.
|
|
|
-- create a CPolygon A |
|
-- result: [0,0] = 0 |
|
|
|
-- copy CPolygon A to a new CPolygon B |
|
-- specify the center values |
|
-- result: [2.5,-2.1] = 0 |
|
|
|
-- create some x and y data |
|
-- create a CPolygon C from arrays |
|
-- calculate the center of mass |
|
-- result: [5.5,-1.25] = 4 |
|
|