SharedJUPYTER_TESTS / pythreejs-s.ipynbOpen in CoCalc
Demo of pythreejs - use plain jupyter server

pythreejs demo in cocalc

Code cells below are from the start of the notebook here:

Do these setup steps in a .term before running this notebook:

pip3 install --user pythreejs
jupyter nbextension install --user --py pythreejs
jupyter nbextension enable --user --py pythreejs
# it may be necessary to restart the jupyter server
smc-jupyter restart

This notebook must be run using "Plain Jupyter Server", which can be launched from lower right of the Project Settings tab (wrench icon) in CoCalc.

from pythreejs import *
import numpy as np
from IPython.display import display
from ipywidgets import HTML, Text, Output, VBox
from traitlets import link, dlink
ball = Mesh(geometry=SphereGeometry(radius=1), 
            material=MeshLambertMaterial(color='red'),
            position=[2, 1, 0])

c = PerspectiveCamera(position=[0, 5, 5], up=[0, 1, 0],
                      children=[DirectionalLight(color='white', position=[3, 5, 1], intensity=0.5)])

scene = Scene(children=[ball, c, AmbientLight(color='#777777')])

renderer = Renderer(camera=c, 
                    scene=scene, 
                    controls=[OrbitControls(controlling=c)])
display(renderer)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.5, position=(3.0, 5.0,…
ball.geometry.radius = 0.5
import time, math
ball.material.color = '#4400dd'
for i in range(1, 150, 2):
    ball.geometry.radius = i / 100.
    ball.position = [math.cos(i / 10.), math.sin(i / 50.), i / 100.]
    time.sleep(.05)