Skip to content

Instantly share code, notes, and snippets.

@karelin
Created May 21, 2017 19:29
Show Gist options
  • Save karelin/c672e388caca75a629bfc8474c7466c2 to your computer and use it in GitHub Desktop.
Save karelin/c672e388caca75a629bfc8474c7466c2 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Basic example\n",
"\n",
"* Simple Python function\n",
"* Shoule be displayed offline"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from pythreejs import *\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f3809bca41834affab44f8e11f38ac1a"
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"nx, ny = (20, 20)\n",
"xmax=1\n",
"x = np.linspace(-xmax, xmax, nx)\n",
"y = np.linspace(-xmax, xmax, ny)\n",
"xx, yy = np.meshgrid(x, y)\n",
"z = xx ** 2 - yy ** 2\n",
"#z[6,1] = float('nan')\n",
"surf_g = SurfaceGeometry(z=list(z[::-1].flat), \n",
" width=2 * xmax,\n",
" height=2 * xmax,\n",
" width_segments=nx - 1,\n",
" height_segments=ny - 1)\n",
"\n",
"surf = Mesh(geometry=surf_g, material=LambertMaterial(map=height_texture(z[::-1], 'YlGnBu_r')))\n",
"surfgrid = SurfaceGrid(geometry=surf_g, material=LineBasicMaterial(color='black'))\n",
"scene = Scene(children=[surf, surfgrid, AmbientLight(color='#777777')])\n",
"c = PerspectiveCamera(position=[0, 3, 3], up=[0, 0, 1], \n",
" children=[DirectionalLight(color='white', position=[3, 5, 1], intensity=0.6)])\n",
"\n",
"Renderer(camera=c, scene = scene, controls=[OrbitControls(controlling=c)])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment