The following example is explained by comments in the code. It is taken from demo5.py. (To
repeat, demo5_light is a function which appears in demo5.py.)
# First we define the mesh and functions on it.
# (Note: nx == ny == nz == 20)
xyz = zeros ((3, nx, ny, nz), Float)
xyz [0] = multiply.outer (span (-1, 1, nx),
ones ((ny, nz), Float))
xyz [1] = multiply.outer (ones (nx, Float),
multiply.outer (span (-1, 1, ny), ones (nz, Float)))
xyz [2] = multiply.outer (ones ((nx, ny), Float),
span (-1, 1, nz))
r = sqrt (xyz [0] ** 2 + xyz [1] ** 2 + xyz [2] ** 2)
theta = arccos (xyz [2] / r)
phi = arctan2 (xyz [1] , xyz [0] + logical_not (r))
y32 = sin (theta) ** 2 * cos (theta) * cos (2 * phi)
# mesh3 creates an object which slice3 can slice. The
# isosurfaces will be with respect to constant values
# of the function r * (1. + y32)].
m3 = mesh3 (xyz, funcs = [r * (1. + y32)])
[nv, xyzv, dum] = slice3 (m3, 1, None, None, value = .50)
# (inner isosurface)
[nw, xyzw, dum] = slice3 (m3, 1, None, None, value = 1.)
# (outer isosurface)
pxy = plane3 (array ([ 0, 0, 1], Float), zeros (3, Float))
pyz = plane3 (array ([ 1, 0, 0], Float), zeros (3, Float))
[np, xyzp, vp] = slice3 (m3, pyz, None, None, 1)
# (pseudo-colored plane slice)
[np, xyzp, vp] = slice2 (pxy, np, xyzp, vp)
# (cut slice in half, discard "back" part)
[nv, xyzv, d1, nvb, xyzvb, d2] = \
slice2x (pxy, nv, xyzv, None) # halve inner isosurface
[nv, xyzv, d1] = \
slice2 (-pyz, nv, xyzv, None)
# (... halve one of those halves)
[nw, xyzw, d1, nwb, xyzwb, d2] = \
slice2x (pxy , nw, xyzw, None)
# (split outer isosurface in halves)
[nw, xyzw, d1] = \
slice2 (-pyz, nw, xyzw, None) # discard half of one half
fma () # frame advance
# split_palette causes isosurfaces to be shaded in grey
# scale, plane sections to be colored by function values
split_palette (" earth.gp")
gnomon (1) # show small set of axes
clear3 () # clears drawing list
set_draw3_(0) # Make sure we don't draw till ready
# Create a tree of objects and put on drawing list
pl3tree (np, xyzp, vp, pyz)
pl3tree (nvb, xyzvb)
pl3tree (nwb, xyzwb)
pl3tree (nv, xyzv)
pl3tree (nw, xyzw)
orient3 ()
# set lighting parameters for isosurfaces
light3 (diffuse = .2, specular = 1)
limits (square= 1)
demo5_light (1) # Causes drawing to appear
demo5.py also contains code which rotates the above object in real-time animation. It is not possible to illustrate that here.