import ipyvolume.pylab as p3
import cortex
import numpy as np
p3.examples.klein_bottle()
%%javascript
// for development, no need to execute this cell
require.onResourceLoad = function(context, map)
{
console.log("loading " +map.name)
// require.undef(map.name);
};
require.undef("nbextensions/ipyvolume/index")
require(["nbextensions/ipyvolume/index"])
from PIL import Image
import urllib.request
url = 'https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif'
url = 'http://www.i-programmer.info/images/stories/News/2015/Mar/A/jupyter.jpg'
im = Image.open(urllib.request.urlopen(url))
pts, polys = cortex.db.get_surf('S1', 'fiducial', merge=True)
pts_flat, polys_flat = cortex.db.get_surf('S1', 'flat', merge=True, nudge=True)
pts_inf, polys_inf = cortex.db.get_surf('S1', 'inflated', merge=True, nudge=True)
x, y, z = pts.T
x_flat, y_flat, z_flat = pts_flat.T
def n(x):
return (x - x.min()) / x.ptp()
u = n(x_flat)
v = n(y_flat)
r = n(x)
g = n(y)
b = n(z)
# go to spherical coordinates
x_inf, y_inf, z_inf = pts_inf.T
r = np.sqrt(x_inf**2 + y_inf**2 + z_inf**2)
phi = np.arctan2(x_inf,-z_inf)
theta = np.arccos(y_inf/r)
r.max()
# clip r
r = np.minimum(r, 60)
r.max()
# back to cartesian
z_sphere = -r * np.sin(theta) * np.cos(phi)
x_sphere = r * np.sin(theta) * np.sin(phi)
y_sphere = r * np.cos(theta)
b = 60
x_box = np.clip(x_inf, -b, b)
y_box = np.clip(y_inf, -b, b)
z_box = np.clip(z_inf, -b, b)
theta = ((theta + (np.pi)) % (2*np.pi)) - (np.pi)
x_flat2 = (phi)*60 #-(((phi+np.pi) % (2*np.pi))- np.pi) * 30
#x_flat = -(((phi+2*np.pi) % (2*np.pi))- np.pi) * 30
y_flat2 = -(theta-np.pi/2) * 30*2
z_flat2 = phi * 0
p3.figure()
p3.style.use('dark')
#p3.style.use(['light', 'minimal'])
print(p3.gcf().style)
x, y, z = pts.T
x2, y2, z2 = pts_flat.T
m = p3.plot_trisurf([x_flat2, x_box, x_sphere, x_inf, x, x_flat],
[y_flat2, y_box, y_sphere, y_inf, y, y_flat],
[z_flat2, z_box, z_sphere, z_inf, z, z_flat], polys_flat, u=u, v=v, texture=im)
p3.animation_control(m, interval=1000)
p3.squarelim()
p3.show()
p3.movie('jupyter-brain.gif')