-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a documentation page with a pythreejs example. #262
Changes from 10 commits
1ff2c30
4ff9861
cc4b9ee
fec1fd8
bd07433
3bd1c79
11124b6
0147b17
44ad474
4335729
caaf55f
3de4dbb
1e3ab29
b808e6f
54e2f24
d2de5a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
================= | ||
pythreejs Example | ||
moorepants marked this conversation as resolved.
Show resolved
Hide resolved
|
||
================= | ||
|
||
Thebe can display output from pythreejs_. The examples are taken from the | ||
moorepants marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pythreejs documentation and are licensed BSD 3 Clause. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A link to https://pythreejs.readthedocs.io/en/stable/examples/ or https://github.com/jupyter-widgets/pythreejs/tree/master/examples might be helpful here. Also, I would change the wording from
to
to match the wording of the other Thebe docs pages and pythreejs's license.
moorepants marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. _pythreejs: https://github.com/jupyter-widgets/pythreejs | ||
|
||
Setup | ||
===== | ||
|
||
Be sure to load require.js before any of your thebe activation code so that the | ||
Jupyter widgets can function: | ||
|
||
.. code-block:: html | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script> | ||
|
||
Configure thebe and load it: | ||
|
||
.. code-block:: html | ||
|
||
<script type="text/x-thebe-config"> | ||
{ | ||
requestKernel: true, | ||
binderOptions: { | ||
repo: "jupyter-widgets/pythreejs", | ||
ref: "2.2.1", | ||
binderUrl: "https://mybinder.org", | ||
repoProvider: "github", | ||
}, | ||
} | ||
</script> | ||
<script src="https://unpkg.com/thebe@latest/lib/index.js"></script> | ||
|
||
Create a button to activate thebe: | ||
|
||
.. code-block:: html | ||
|
||
<button id="activateButton" style="width: 120px; height: 40px; font-size: 1.5em;"> | ||
Activate | ||
</button> | ||
<script> | ||
var bootstrapThebe = function() { | ||
thebelab.bootstrap(); | ||
} | ||
document.querySelector("#activateButton").addEventListener('click', bootstrapThebe) | ||
</script> | ||
|
||
Now add code cells between these HTML tags: | ||
|
||
.. code-block:: html | ||
|
||
<pre data-executable="true" data-language="python"></pre> | ||
|
||
Examples | ||
======== | ||
|
||
.. raw:: html | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script> | ||
<script type="text/x-thebe-config"> | ||
{ | ||
requestKernel: true, | ||
binderOptions: { | ||
repo: "jupyter-widgets/pythreejs", | ||
ref: "2.2.1", | ||
binderUrl: "https://mybinder.org", | ||
repoProvider: "github", | ||
}, | ||
} | ||
</script> | ||
<script src="https://unpkg.com/thebe@latest/lib/index.js"></script> | ||
|
||
Press the "Activate" button below to connect to a Jupyter server: | ||
|
||
.. raw:: html | ||
|
||
<button id="activateButton" style="width: 120px; height: 40px; font-size: 1.5em;"> | ||
Activate | ||
</button> | ||
<script> | ||
var bootstrapThebe = function() { | ||
thebelab.bootstrap(); | ||
} | ||
document.querySelector("#activateButton").addEventListener('click', bootstrapThebe) | ||
</script> | ||
|
||
Primitive shapes can be displayed: | ||
|
||
.. raw:: html | ||
|
||
<pre data-executable="true" data-language="python"> | ||
from pythreejs import BoxGeometry | ||
BoxGeometry( | ||
width=5, | ||
height=10, | ||
depth=15, | ||
widthSegments=5, | ||
heightSegments=10, | ||
depthSegments=15) | ||
</pre> | ||
|
||
More complex shapes can be constructed and viewed: | ||
|
||
.. raw:: html | ||
|
||
<pre data-executable="true" data-language="python"> | ||
from IPython.display import display | ||
from pythreejs import (ParametricGeometry, Mesh, PerspectiveCamera, Scene, | ||
MeshLambertMaterial, DirectionalLight, AmbientLight, | ||
Renderer, OrbitControls, PerspectiveCamera) | ||
|
||
f = """ | ||
function f(origu, origv, out) { | ||
// scale u and v to the ranges I want: [0, 2*pi] | ||
var u = 2*Math.PI*origu; | ||
var v = 2*Math.PI*origv; | ||
|
||
var x = Math.sin(u); | ||
var y = Math.cos(v); | ||
var z = Math.cos(u+v); | ||
|
||
out.set(x,y,z) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this line should have a semicolon. I've tested it with one and it works as intended.
moorepants marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
""" | ||
surf_g = ParametricGeometry(func=f, slices=16, stacks=16); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, this line probably shouldn't have a semicolon. It also works without it as intended.
moorepants marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
surf = Mesh(geometry=surf_g, material=MeshLambertMaterial(color='green', side='FrontSide')) | ||
surf2 = Mesh(geometry=surf_g, material=MeshLambertMaterial(color='yellow', side='BackSide')) | ||
c = PerspectiveCamera(position=[5, 5, 3], up=[0, 0, 1], | ||
children=[DirectionalLight(color='white', | ||
position=[3, 5, 1], | ||
intensity=0.6)]) | ||
scene = Scene(children=[surf, surf2, c, AmbientLight(intensity=0.5)]) | ||
renderer = Renderer(camera=c, scene=scene, controls=[OrbitControls(controlling=c)], width=400, height=400) | ||
display(renderer) | ||
</pre> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every other title is capitalized, maybe this one should be too.