TSeries
The TSeries function creates an array (Lua table) containing equally spaced values. Use this function to create a table like {1,2,3,4,...} or {5.0,4.6,4.2,3.8,...}.
array = TSeries( nCount )
array = TSeries( nCount, nStart, nStep )
where
nCount is the number of values to create,
nStart is the first number of the series (defaults to 1),
nStep is the interval, or step value, between numbers in the series (defaults to 1),
array is a new table containing the series.
Use ths method to quickly create an array of equally spaced numbers. If working with a specific starting value and ending value, note that nCount+1 values are required to include the endpoints of the range (nEnd - nStart) / nCount. In other words, nStep = (nEnd - nStart) / (nCount – 1).
The following script creates a table containing 1000 integer values from 1 to 1000.
|
-- create a table of 1000 numbers as 1, 2, 3, ..., 1000. |
The following example creates a table containing a series of 11 numbers decreasing from 5.0 to 1.0 with a step of -0.4. Note that 11 numbers is chosen to finish the series at 0.4. This is given by -0.4 = (1.0-5.0)/(11-1).
|
-- create a table of 11 numbers from 5.0 through 1.0. |
The next example creates a 6x4 pixel image of integer data type using the CImage:newarray method and the TSeries() function. The 24 pixels of the image are initializedwith a series of values from 1 through 24. This technique can be useful for creating test images having a unique, known pixel value that traces each pixel coordinate. Using nCount=6*4 instead of nCount=24 is done only to show the relationship to the image dimensions {6,4}:
|
-- create a new CImage |