import k3d
import numpy as np
N = 100
theta = np.linspace(0, 2.0 * np.pi, N)
phi = np.linspace(0, 2.0 * np.pi, N)
theta, phi = np.meshgrid(theta, phi)
c, a = 2, 1
x = (c + a * np.cos(theta)) * np.cos(phi)
y = (c + a * np.cos(theta)) * np.sin(phi)
z = a * np.sin(theta)
vertices = np.dstack([x, y, z]).astype(np.float32)
indices = (np.stack([
np.arange(N*N - N - 1) + 0, np.arange(N*N - N - 1) + N, np.arange(N*N - N - 1) + N + 1,
np.arange(N*N - N - 1) + 0, np.arange(N*N - N - 1) + N + 1, np.arange(N*N - N - 1) + 1
]).T).astype(np.uint32)
plot = k3d.plot()
points = k3d.points(vertices, point_size=0.05, shader='3d', color=0)
mesh = k3d.mesh(vertices, indices, flat_shading=False,
shader='mesh',
attribute=phi,
color_map=k3d.matplotlib_color_maps.twilight,
color=0x00ff00)
wire = k3d.lines(vertices, indices, flat_shading=False,
shader='mesh', width=0.003,
indices_type='segment',
color=0)
plot += mesh
plot += wire
plot += points
plot.display()