-
Notifications
You must be signed in to change notification settings - Fork 66
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
Merged
moorepants
merged 16 commits into
jupyter-book:master
from
moorepants:pythreejs-example
Aug 13, 2021
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1ff2c30
Added a documentation page with a pythreejs example.
moorepants 4ff9861
Added require.js script and avoided using display.
moorepants cc4b9ee
Described the setup in the pythreejs example.
moorepants fec1fd8
Minor text edits.
moorepants bd07433
Fixed merge conflict.
moorepants 3bd1c79
Moved pythreejs example into example dir.
moorepants 11124b6
Point to thebe not thebelab.
moorepants 0147b17
Use mybinder.org.
moorepants 44ad474
Merge branch 'master' into pythreejs-example
moorepants 4335729
Merge branch 'master' into pythreejs-example
moorepants caaf55f
Update docs/examples/pythreejs-example.rst
moorepants 3de4dbb
Update docs/examples/pythreejs-example.rst
moorepants 1e3ab29
Update docs/examples/pythreejs-example.rst
moorepants b808e6f
Update docs/examples/pythreejs-example.rst
moorepants 54e2f24
Update docs/examples/pythreejs-example.rst
moorepants d2de5a9
Fixed merge conflict.
moorepants File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
================= | ||
PyThreeJs Example | ||
================= | ||
|
||
Thebe can display output from pythreejs_. The examples are taken from the | ||
pythreejs documentation and are licensed BSD 3 Clause. | ||
|
||
.. _pythreejs: https://github.com/jupyter-widgets/pythreejs | ||
|
||
Be sure to load require.js before any of your thebe activation code:: | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script> | ||
|
||
.. raw:: html | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.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> | ||
|
||
.. raw:: html | ||
|
||
<script type="text/x-thebe-config"> | ||
{ | ||
requestKernel: true, | ||
binderOptions: { | ||
repo: "jupyter-widgets/pythreejs", | ||
ref: "2.2.1", | ||
moorepants marked this conversation as resolved.
Show resolved
Hide resolved
|
||
binderUrl: "https://binder.libretexts.org", | ||
moorepants marked this conversation as resolved.
Show resolved
Hide resolved
|
||
repoProvider: "github", | ||
}, | ||
} | ||
</script> | ||
<script src="https://unpkg.com/thebelab@latest/lib/index.js"></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) | ||
} | ||
""" | ||
surf_g = ParametricGeometry(func=f, slices=16, stacks=16); | ||
|
||
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) | ||
surf | ||
</pre> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would it make more sense to add the example under examples section of the docs?
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.
Yes, but none of those are in the Sphinx docs. This table of contents
toc
typically shows all the rst files. The examples inexamples/
need to be moved into the Sphinx docs and then we could have an examples section in the table of contents.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.
maybe creating an examples directory in the sphinx docs is appropriate for these? It might make sense to move all of the existing examples in there
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.
Can do.
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.
+1 to moving all of our example pages to
examples/
and adding a section in the docs for them specificallyI don't know that we need a separate index file for
examples
, we can just link them from the front page like:does that make sense?