Multiple LightingΒΆ

../../_images/lower_light1.png

Using the vertical direction for gradient color mapping, lighting is simulated from below. Surface shading is then applied from the standard direction with added highlighting to simulate spot lighting. The overall effect is lighting from three source directions.

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

#.. simulation of two light sources: cmap normals and highlighting

# 1. Define function to examine .....................................

def swirl(rtv) :
    r,t,v = rtv
    R = 2 + np.sin(7*t + 5*v)
    return R,t,v

vertical = lambda rtp : s3d.SphericalSurface.coor_convert(rtp,True)[2]

# 2. Setup and map surfaces .........................................
cmap = cmu.hsv_cmap_gradient([0.14,1,1],[0.14,1,0.3],'lowlite')

surface = s3d.SphericalSurface.grid(180,7*90,minrad=0.01)
surface.map_geom_from_op( swirl )
surface.map_cmap_from_op( vertical , cmap )
surface.shade().hilite(direction=[-.4,-1,1],focus=2.5)

# 3. Construct figure, add surface, plot ............................
minmax=(-2.7,2.7)
fig = plt.figure(figsize=plt.figaspect(1) )
ax = plt.axes(projection='3d',facecolor='k')
ax.view_init(30,-130)
ax.set_axis_off()
ax.set(xlim=minmax, ylim=minmax, zlim=minmax )

ax.add_collection3d(surface)

fig.tight_layout(pad=0)
plt.show()