generated from jupyterlite/demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b37f75
commit 7b7ddae
Showing
3 changed files
with
284 additions
and
191 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,284 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Getting Started with COMPAS" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Through [Jupyterlite](https://jupyterlite.readthedocs.io/en/stable/) and [Pyodide](https://pyodide.org/en/stable/) (a WebAssembly port of CPython), you can use the core COMPAS library and some of its extensions directly in the browser; no server running in the background, and no need to install anything on your computer." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Installation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The current build of Pyodide doesn't include COMPAS packages by default. We still have to install the packages we want to use with `pip`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 27, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Requirement already satisfied: jsonschema in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (4.21.1)\n", | ||
"Requirement already satisfied: networkx in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (3.2.1)\n", | ||
"Requirement already satisfied: numpy in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (1.22.1)\n", | ||
"Requirement already satisfied: scipy in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (1.7.3)\n", | ||
"Requirement already satisfied: pythreejs in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (2.4.2)\n", | ||
"Requirement already satisfied: referencing>=0.28.4 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from jsonschema) (0.32.1)\n", | ||
"Requirement already satisfied: rpds-py>=0.7.1 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from jsonschema) (0.17.1)\n", | ||
"Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from jsonschema) (2023.12.1)\n", | ||
"Requirement already satisfied: attrs>=22.2.0 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from jsonschema) (23.2.0)\n", | ||
"Requirement already satisfied: traitlets in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from pythreejs) (5.14.1)\n", | ||
"Requirement already satisfied: ipydatawidgets>=1.1.1 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from pythreejs) (4.3.5)\n", | ||
"Requirement already satisfied: ipywidgets>=7.2.1 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from pythreejs) (8.1.1)\n", | ||
"Requirement already satisfied: traittypes>=0.2.0 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipydatawidgets>=1.1.1->pythreejs) (0.2.1)\n", | ||
"Requirement already satisfied: ipython>=6.1.0 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipywidgets>=7.2.1->pythreejs) (8.12.0)\n", | ||
"Requirement already satisfied: comm>=0.1.3 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipywidgets>=7.2.1->pythreejs) (0.2.1)\n", | ||
"Requirement already satisfied: jupyterlab-widgets~=3.0.9 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipywidgets>=7.2.1->pythreejs) (3.0.9)\n", | ||
"Requirement already satisfied: widgetsnbextension~=4.0.9 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipywidgets>=7.2.1->pythreejs) (4.0.9)\n", | ||
"Requirement already satisfied: jedi>=0.16 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.19.1)\n", | ||
"Requirement already satisfied: pickleshare in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.7.5)\n", | ||
"Requirement already satisfied: pygments>=2.4.0 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (2.17.2)\n", | ||
"Requirement already satisfied: appnope in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.1.3)\n", | ||
"Requirement already satisfied: backcall in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.2.0)\n", | ||
"Requirement already satisfied: pexpect>4.3 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (4.9.0)\n", | ||
"Requirement already satisfied: matplotlib-inline in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.1.6)\n", | ||
"Requirement already satisfied: stack-data in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.6.2)\n", | ||
"Requirement already satisfied: decorator in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (5.1.1)\n", | ||
"Requirement already satisfied: typing-extensions in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (4.9.0)\n", | ||
"Requirement already satisfied: prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (3.0.43)\n", | ||
"Requirement already satisfied: parso<0.9.0,>=0.8.3 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.8.3)\n", | ||
"Requirement already satisfied: ptyprocess>=0.5 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from pexpect>4.3->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.7.0)\n", | ||
"Requirement already satisfied: wcwidth in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.2.13)\n", | ||
"Requirement already satisfied: executing>=1.2.0 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (2.0.1)\n", | ||
"Requirement already satisfied: asttokens>=2.1.0 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (2.4.1)\n", | ||
"Requirement already satisfied: pure-eval in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.2.2)\n", | ||
"Requirement already satisfied: six>=1.12.0 in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (from asttokens>=2.1.0->stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (1.16.0)\n", | ||
"Note: you may need to restart the kernel to use updated packages.\n", | ||
"zsh:1: 2.0.0b4 not found\n", | ||
"Note: you may need to restart the kernel to use updated packages.\n", | ||
"Requirement already satisfied: compas_notebook in /Users/vanmelet/opt/miniconda3/envs/compas-dev/lib/python3.9/site-packages (0.2.4)\n", | ||
"Note: you may need to restart the kernel to use updated packages.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%pip install jsonschema networkx numpy scipy pythreejs\n", | ||
"%pip install compas>=2.0.0b4 --no-deps\n", | ||
"%pip install compas_notebook --no-deps" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Verify that the installation was succesful and that we have the correct version" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 28, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'2.0.0-beta.4-b812aead'" | ||
] | ||
}, | ||
"execution_count": 28, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import compas\n", | ||
"compas.__version__" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Basic Example" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"As a basic example, we create a mesh from a unit-sized box geometry, apply catmull-clark subdivision, and export the mesh to an OBJ file." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"First import a box from the geometry package." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 29, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from compas.geometry import Box" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Then create and convert the box in a few simple steps." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 30, | ||
"metadata": { | ||
"trusted": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"box = Box(xsize=1, ysize=1, zsize=1)\n", | ||
"mesh = box.to_mesh()\n", | ||
"ball = mesh.subdivided(k=3)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Print some basic mesh information." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 31, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"<Mesh with 386 vertices, 384 faces, 768 edges>\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(ball)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Convert the ball to an OBJ file." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 32, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ball.to_obj('ball.obj')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Visualization" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"With the Notebook viewer of `compas_notebook`, we can visualize the mesh in a mini interactive environment." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 43, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "ba0d6efcf3424366978704c5fa1c5584", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"VBox(children=(HBox(children=(Button(icon='folder-open', layout=Layout(height='32px', width='48px'), style=But…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"from compas_notebook.viewer import Viewer\n", | ||
"\n", | ||
"viewer = Viewer(camera={'position': [1, -2, 1], 'target': [0, 0, 0]})\n", | ||
"viewer.scene.add(ball, color='#cccccc', show_vertices=False)\n", | ||
"viewer.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "compas-dev", | ||
"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.9.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.