Texture Surface with Geometric MappingΒΆ

../../_images/avacado1.png

Three custom colormaps were created for this visualization.

../../_images/avacado_cmap.png
from matplotlib import pyplot as plt
import numpy as np
import s3dlib.surface as s3d
import s3dlib.cmap_utilities as cmu

#.. Texture Surface with Geometric Mapping

# 1. Define functions to examine ....................................

def randfunc(rtz) :
    r,t,z = rtz
    sigma = 0.01
    R = r + sigma*np.random.rand( len(r) )
    return R,t,z

def ava_func(rtp) :
    r,t,p = rtp
    delta, tmax = 0.1, 0.7
    P = 2*p/tmax
    Rt = (1-delta) + delta*np.cos(P)
    R = r*np.where(P>2*np.pi, 1.0 , Rt)
    return R,t,p

def ava_edge(rtz) :
    r,t,z = rtz
    tb = 2*np.pi - t
    T = np.where(t<np.pi,t,tb)
    # use the ava_func only to calc R
    rr = np.full(len(r),0.98)
    R = r*ava_func([rr, z, T])[0]
    return R,t,z

# 2. Setup and map surfaces .........................................
rez=6
cmu.rgb_cmap_gradient('darkolivegreen', 'olive',  name='skin' )
cmu.rgb_cmap_gradient('saddlebrown', 'sienna',    name='seed' )
cmu.rgb_cmap_gradient('saddlebrown', 'darkkhaki', name='pulp' )

skin = s3d.SphericalSurface(rez,basetype='octa')
skin.map_geom_from_op(randfunc)
skin.map_cmap_from_op( lambda rtz : rtz[0], 'skin' )
skin.map_geom_from_op( lambda rtp : ava_func(rtp) )
skin.shade().hilite(.3,direction=[0,1,1])
skin.clip( lambda xyz : xyz[0]>0 , usexyz=True )

pulp = s3d.PolarSurface(rez, basetype='squ')
pulp.map_cmap_from_op( lambda rtz : rtz[0] , 'pulp'  )
pulp.map_geom_from_op(ava_edge)
pulp.transform( [ [0,0,1], [0,1,0], [1,0,0] ] )

seed =  s3d.SphericalSurface(rez,basetype='octa')
seed.map_cmap_from_op( lambda rtp : randfunc(rtp)[0], 'seed' )
seed.transform(scale=.4,translate=[0,0,-.1]).shade()

avacado = pulp + skin + seed

# 3. Construct figure, add surfaces, and plot ......................

fig = plt.figure(figsize=plt.figaspect(1))
info = str(avacado) 
fig.text(0.975,0.975,info, ha='right', va='top', fontsize='smaller', multialignment='right')
ax = fig.add_subplot(111, projection='3d', aspect='equal')
minmax = (-.8,.8)
ax.set(xlim=minmax, ylim=minmax, zlim=minmax )
ax.set_axis_off()
ax.view_init(elev=10, azim=125)

ax.add_collection3d(avacado)

fig.tight_layout()
plt.show()