diff --git a/GETTING-STARTED.md b/GETTING-STARTED.md
index ccdf5669..a7b21406 100644
--- a/GETTING-STARTED.md
+++ b/GETTING-STARTED.md
@@ -7,23 +7,21 @@ This page will guide you through getting started with PyScript.
PyScript does not require any development environment other
than a web browser. We recommend using Chrome.
+If, you're using [VSCode](https://code.visualstudio.com/) the
+[Live Server extension](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)
+can be used to reload the page as you edit the HTML file.
+
## Installation
-First, go to https://pyscript.net and download the PyScript assets.
-Unzip the archive to a directory where you wish to write PyScript-enabled
-HTML files. You should then have three files in your directory.
+There is no installation required. In this document we'll use
+the PyScript assets served on https://pyscript.net.
-```
-├── ./
-│ ├── pyscript.css
-│ ├── pyscript.js
-│ └── pyscript.js.map
-```
+If you want to download the source and build it yourself follow
+the instructions in the README.md file.
## Your first PyScript HTML file
-Here's a "Hello, world!" example using PyScript using the assets you
-downloaded from https://pyscript.net.
+Here's a "Hello, world!" example using PyScript
Using your favorite editor create a new file called `hello.html` in
the same directory as your PyScript JavaScript and CSS files with the
@@ -33,8 +31,8 @@ open an HTML by double clicking it in your file explorer.
```html
-
-
+
+
print('Hello, World!')
@@ -53,8 +51,8 @@ example we can compute π.
```html
-
-
+
+
@@ -85,8 +83,8 @@ the `` tag write to.
```html
-
-
+
+
@@ -124,6 +122,8 @@ HTML head. You can also link to `.whl` files directly on disk like in our [toga
```
+If your `.whl` is not a pure Python wheel then open a PR or issue with [pyodide](https://github.com/pyodide/pyodide) to get it added here https://github.com/pyodide/pyodide/tree/main/packages
+
For example, NumPy and Matplotlib are available. Notice here we're using ``
as a shortcut, which takes the expression on the last line of the script and runs `pyscript.write('plot', fig)`.
@@ -131,8 +131,8 @@ as a shortcut, which takes the expression on the last line of the script and run
```html
-
-
+
+
- numpy
- matplotlib
@@ -157,4 +157,52 @@ fig
```
-If your `.whl` is not a pure Python wheel then open a PR or issue with [pyodide](https://github.com/pyodide/pyodide) to get it added here https://github.com/pyodide/pyodide/tree/main/packages
\ No newline at end of file
+### Local modules
+
+In addition to packages you can declare local Python modules that will
+be imported in the `` tag. For example we can place the random
+number generation steps in a function in the file `data.py`.
+
+```python
+# data.py
+import numpy as np
+
+def make_x_and_y(n):
+ x = np.random.randn(n)
+ y = np.random.randn(n)
+ return x, y
+```
+
+In the HTML tag `` paths to local modules are provided in the
+`paths:` key.
+
+```html
+
+
+
+
+
+ - numpy
+ - matplotlib
+ - paths:
+ - /data.py
+
+
+
+
+
Let's plot random numbers
+
+
+import matplotlib.pyplot as plt
+from data import make_x_and_y
+
+x, y = make_x_and_y(n=1000)
+
+fig, ax = plt.subplots()
+ax.scatter(x, y)
+fig
+
+
+
+```
+
diff --git a/README.md b/README.md
index 94b45f3c..46bf566f 100644
--- a/README.md
+++ b/README.md
@@ -16,8 +16,8 @@ PyScript is a meta project that aims to combine multiple open technologies to cr
To try PyScript, import the pyscript to your html page with:
```
-
-
+
+
```
At that point, you can then use PyScript components in your html page. PyScript currently implements the following elements:
@@ -35,6 +35,12 @@ To contribute:
* install the dependencies with `npm install` - make sure to use nodejs version >= 16
* run `npm run dev` to build and run the dev server. This will also watch for changes and rebuild when a file is saved
+## Resources
+
+* [Discussion board](https://community.anaconda.cloud/c/tech-topics/pyscript)
+* [Home Page](https://pyscript.net/)
+* [Blog Post](https://engineering.anaconda.com/2022/04/welcome-pyscript.html)
+
## Notes
* This is an extremely experimental project, so expect things to break!
diff --git a/pyscriptjs/examples/fractals.py b/pyscriptjs/examples/fractals.py
index 8d4ad78e..65e0f31a 100644
--- a/pyscriptjs/examples/fractals.py
+++ b/pyscriptjs/examples/fractals.py
@@ -1,4 +1,6 @@
+from typing import Tuple
import numpy as np
+from numpy.polynomial import Polynomial
def mandelbrot(width: int, height: int, *,
x: float = -0.5, y: float = 0, zoom: int = 1, max_iterations: int = 100) -> np.array:
@@ -60,3 +62,48 @@ def julia(width: int, height: int, *,
div_time[m] = i
return div_time
+
+Range = Tuple[float, float]
+
+def newton(width: int, height: int, *,
+ p: Polynomial, a: complex, xr: Range = (-2.5, 1), yr: Range = (-1, 1), max_iterations: int = 100) -> (np.array, np.array):
+ """ """
+ # To make navigation easier we calculate these values
+ x_from, x_to = xr
+ y_from, y_to = yr
+
+ # Here the actual algorithm starts
+ x = np.linspace(x_from, x_to, width).reshape((1, width))
+ y = np.linspace(y_from, y_to, height).reshape((height, 1))
+ z = x + 1j*y
+
+ # Compute the derivative
+ dp = p.deriv()
+
+ # Compute roots
+ roots = p.roots()
+ epsilon = 1e-5
+
+ # Set the initial conditions
+ a = np.full(z.shape, a)
+
+ # To keep track in which iteration the point diverged
+ div_time = np.zeros(z.shape, dtype=int)
+
+ # To keep track on which points did not converge so far
+ m = np.full(a.shape, True, dtype=bool)
+
+ # To keep track which root each point converged to
+ r = np.full(a.shape, 0, dtype=int)
+
+ for i in range(max_iterations):
+ z[m] = z[m] - a[m]*p(z[m])/dp(z[m])
+
+ for j, root in enumerate(roots):
+ converged = (np.abs(z.real - root.real) < epsilon) & (np.abs(z.imag - root.imag) < epsilon)
+ m[converged] = False
+ r[converged] = j + 1
+
+ div_time[m] = i
+
+ return div_time, r
diff --git a/pyscriptjs/examples/numpy_canvas_fractals.html b/pyscriptjs/examples/numpy_canvas_fractals.html
index cbee92fb..2247747d 100644
--- a/pyscriptjs/examples/numpy_canvas_fractals.html
+++ b/pyscriptjs/examples/numpy_canvas_fractals.html
@@ -1,6 +1,6 @@
- Visualization of Mandelbrot and Julia sets with NumPy and HTML5 canvas
+ Visualization of Mandelbrot, Julia and Newton sets with NumPy and HTML5 canvas
@@ -17,6 +17,10 @@
animation: spin 1s ease-in-out infinite;
}
+ canvas {
+ display: none;
+ }
+
@keyframes spin {
to {
transform: rotate(360deg);
@@ -28,35 +32,68 @@
-