| Home | zeGraph lib | Lua lib | Custom lib | Tutorials | Notes | XML Script | C-Talk | Z-Script |
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19

Lesson 15 Math Package

The math package contains basic C math functions and some higher level math functions. zeArray objects of double floating type are usually used for input and output. For example, a call to zeMath.cos(rr) will apply the cos function to all elements of arr. Triagnometrical functions of zeMath treat array elements as angles in radius.

require("register")
arr = zeUtl.new("double")
arr:range(1, 1, 5)
zeMath.cos(arr);
arr:reshape(1, 5)
arr:print()
--[[Outputs:
5.403023e-001,-4.161468e-001,-9.899925e-001,-6.536436e-001,2.836622e-001
]]

The Template Numerical Toolkit is used for basic matrix operations on zeArray object, for multi-linear regression, and for non-linear smoothing of data. We would like to peticularly memtion the Perlin noise functions here. It is implemented for generating texture.

require("register")

render, scene, root = zeGrf.new("render", "scene", "node")
render:add(scene)
scene:set{node = root}

point, xyz, clr = zeGrf.new("point", "vertex", "color")
root:add(point)
point:set{vertex = xyz, vertex_color = clr}

per, arr, arr2 = zeUtl.new("double", "double", "double")
arr:resize(200, 200)
zeMath.rand(arr)
zeMath.perlin(per, 6, arr)
zeMake.grid2points(arr2, 1, per)

xyz:add(arr2)

n = arr2:size()
per:resize(n, 1)
per:fill(0)
arr2:setarr(0, per)
arr2:setarr(1, per)
arr2:insert(3, per)

clr:add(arr2)

root:translate(-100, -100, 0)

render:tofile("perlin_texture.png")

perlin_texture.png