quick_2d.lua
NAME
quick_2d
FUNCTION
quick_2d(width, height, x, y)
NOTES
Creates a quick 2D-plot of points.
x will be modified on return.
INPUTS
width - image width
height - image height
x, y - 1D zeArray object of double
OUTPUTS
a zeRender object, a zeNode object, and a zePlot object
SOURCE
require("register")
function quick_2d(width, height, x, y)
local render, scene, root, plot, font, point, xy
= zeGrf.new("render", "scene", "node", "plot", "font", "point", "vertex")
render:add(scene)
render:set{size = {width, height}}
scene:set{node = root, viewport = {0, 0, width, height}}
root:add(plot)
plot:add(point)
plot:font(font)
point:set{vertex = xy, size = 5, color = {0, 0, 1, 1}}
local xscale = 0.6
local yscale = 0.6
local xmin = x:min()
local xmax = x:max()
local ymin = y:min()
local ymax = y:max()
local dx = (xmax - xmin) / 6
local dy = (ymax - ymin) / 6
plot:scale(xscale, yscale, 1)
plot:set{axis = "x", range = {xmin, xmax}, tickdigit = {1, false},
tickmarks = {xmin, dx, 0}, ticklength = 1.5, linewidth = 1.5,
label = "X", offset = {0, -height * yscale / 2, 0}}
plot:set{axis = "y", range = {ymin, ymax}, tickdigit = {1, false},
tickmarks = {ymin, dy, 0}, ticklength = 1.5, linewidth = 1.5,
label = "Y", offset = {-width * xscale / 2, 0, 0}}
x:insert(1, y)
x:insert(2, 0)
xy:add(x)
return render, root, plot
end