pyctures 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyctures-0.1.0/LICENSE +21 -0
- pyctures-0.1.0/PKG-INFO +196 -0
- pyctures-0.1.0/README.md +161 -0
- pyctures-0.1.0/THIRD-PARTY-NOTICES +53 -0
- pyctures-0.1.0/pyproject.toml +56 -0
- pyctures-0.1.0/setup.cfg +4 -0
- pyctures-0.1.0/src/pyctures/__init__.py +890 -0
- pyctures-0.1.0/src/pyctures/__main__.py +5 -0
- pyctures-0.1.0/src/pyctures/_worker.py +89 -0
- pyctures-0.1.0/src/pyctures/build.py +198 -0
- pyctures-0.1.0/src/pyctures/cli.py +48 -0
- pyctures-0.1.0/src/pyctures/pages.py +187 -0
- pyctures-0.1.0/src/pyctures/server.py +408 -0
- pyctures-0.1.0/src/pyctures/web/pyctures.js +1260 -0
- pyctures-0.1.0/src/pyctures/web/three/LICENSE +21 -0
- pyctures-0.1.0/src/pyctures/web/three/OrbitControls.js +1860 -0
- pyctures-0.1.0/src/pyctures/web/three/three.core.min.js +6 -0
- pyctures-0.1.0/src/pyctures/web/three/three.module.min.js +6 -0
- pyctures-0.1.0/src/pyctures.egg-info/PKG-INFO +196 -0
- pyctures-0.1.0/src/pyctures.egg-info/SOURCES.txt +27 -0
- pyctures-0.1.0/src/pyctures.egg-info/dependency_links.txt +1 -0
- pyctures-0.1.0/src/pyctures.egg-info/entry_points.txt +2 -0
- pyctures-0.1.0/src/pyctures.egg-info/requires.txt +4 -0
- pyctures-0.1.0/src/pyctures.egg-info/top_level.txt +1 -0
- pyctures-0.1.0/tests/test_browser.py +278 -0
- pyctures-0.1.0/tests/test_images.py +205 -0
- pyctures-0.1.0/tests/test_runtime.py +342 -0
- pyctures-0.1.0/tests/test_server_build.py +192 -0
- pyctures-0.1.0/tests/test_worker.py +335 -0
pyctures-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 John Wylie
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pyctures-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyctures
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python 2D and 3D graphics, drawn in your web browser. Games, animations, charts and 3D scenes.
|
|
5
|
+
Author: John Wylie
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/johnwylie70/pyctures
|
|
8
|
+
Project-URL: Documentation, https://github.com/johnwylie70/pyctures/tree/main/docs
|
|
9
|
+
Project-URL: Source, https://github.com/johnwylie70/pyctures
|
|
10
|
+
Project-URL: Issues, https://github.com/johnwylie70/pyctures/issues
|
|
11
|
+
Keywords: graphics,canvas,3d,three.js,games,animation,education,pyodide
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Education
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Games/Entertainment
|
|
24
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
25
|
+
Classifier: Topic :: Multimedia :: Graphics :: 3D Rendering
|
|
26
|
+
Classifier: Topic :: Education
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
License-File: THIRD-PARTY-NOTICES
|
|
31
|
+
Provides-Extra: test
|
|
32
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
33
|
+
Requires-Dist: playwright>=1.40; extra == "test"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# Pyctures
|
|
37
|
+
|
|
38
|
+
Pyctures ("Python pictures") gives Python the full set of JavaScript graphics functions: the web's 2D canvas for 2D, and three.js for 3D. Write a short Python program and it draws in your web browser: shapes, text, moving sprites, games, animations, live charts and lit 3D scenes. The names are the ones JavaScript uses, so any JavaScript graphics example can be brought across easily. Run a scene with your own Python while you write it, then build it into a folder that runs in any browser, on any website.
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install pyctures
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Python 3.9 or newer. Nothing else is installed.
|
|
49
|
+
|
|
50
|
+
## A first scene
|
|
51
|
+
|
|
52
|
+
Save this as `hello.py`:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import math
|
|
56
|
+
|
|
57
|
+
def draw():
|
|
58
|
+
ctx.fill_style = "midnightblue"
|
|
59
|
+
ctx.fill_rect(0, 0, width, height)
|
|
60
|
+
for i in range(12):
|
|
61
|
+
ctx.fill_style = f"hsl({i * 30}, 80%, 60%)"
|
|
62
|
+
ctx.begin_path()
|
|
63
|
+
ctx.arc(width / 2 + 120 * math.cos(i / 1.91), height / 2 + 120 * math.sin(i / 1.91), 20, 0, math.tau)
|
|
64
|
+
ctx.fill()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`draw()` is called every frame, `ctx` is the 2D drawing surface, and `width` and `height` are the size of the canvas. There is nothing to import.
|
|
68
|
+
|
|
69
|
+
## Run it
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pyctures run hello.py
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Your browser opens on the scene. The program runs in your own Python, so numpy and anything else you have installed works. Save the file and the scene runs again. Errors are shown on the page with the line they happened on.
|
|
76
|
+
|
|
77
|
+
Options: `--port 9000`, `--no-browser`.
|
|
78
|
+
|
|
79
|
+
## Share it
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pyctures build hello.py -o site/
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`site/` is a folder of plain files that runs the scene entirely in the browser, with [Pyodide](https://pyodide.org) loaded from its official CDN. Put it on any static host. Every path in it is relative.
|
|
86
|
+
|
|
87
|
+
Or make one file:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pyctures build hello.py -o hello.html
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`hello.html` holds the scene and everything it needs (three.js too, if the scene is 3D), so you can email it, put it on any website, or open it straight from your disk. Python still loads from Pyodide's CDN.
|
|
94
|
+
|
|
95
|
+
Either way, images the scene loads by a relative path, such as `load_image("textures/brick.png")` or `THREE.TextureLoader().load("textures/brick.png")`, are included automatically: copied into the folder, or packed into the one file. A named image that is missing is reported as a warning.
|
|
96
|
+
|
|
97
|
+
Python runs in a background thread of the browser (a Web Worker), and the page only draws. A slow frame or a stuck loop cannot hold up the page, so scenes play smoothly on phones and tablets too. Add `?measure=1` to the address to see the frame rate and where each frame's time goes.
|
|
98
|
+
|
|
99
|
+
## Use it on your website
|
|
100
|
+
|
|
101
|
+
Either put a built scene in an iframe:
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<iframe src="hello/index.html" style="width: 100%; aspect-ratio: 16 / 9; border: 0"></iframe>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
or put scenes straight into your page, as many as you like:
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<div data-pyctures-src="balls.py"></div>
|
|
111
|
+
<div data-pyctures-src="knot.py" style="height: 420px"></div>
|
|
112
|
+
<script type="module" src="pyctures/pyctures.js"></script>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Each canvas fills its box, starts when it scrolls into view, and pauses when it is out of view or the tab is hidden. All the scenes on a page share one copy of Python, in a background thread. `pyctures build my-page/ -o site/` copies your page and adds the `pyctures/` folder. See [Use it on your website](docs/website.md), and the two-scene page in [`examples/website`](examples/website).
|
|
116
|
+
|
|
117
|
+
## Bringing a JavaScript example across
|
|
118
|
+
|
|
119
|
+
The calls are the same; a few things are written the Python way.
|
|
120
|
+
|
|
121
|
+
| JavaScript | Python |
|
|
122
|
+
|---|---|
|
|
123
|
+
| `new THREE.Mesh(g, m)` | `THREE.Mesh(g, m)` |
|
|
124
|
+
| `{ color: 0x44aaff, roughness: 0.4 }` | `color=0x44aaff, roughness=0.4` |
|
|
125
|
+
| `const x = 1;` `let y = 2;` | `x = 1` `y = 2` |
|
|
126
|
+
| `ctx.fillStyle = "red"` | the same, or `ctx.fill_style = "red"` |
|
|
127
|
+
| a `requestAnimationFrame` loop | `def draw():` and `def update(dt):` |
|
|
128
|
+
| `canvas.addEventListener("click", (e) => …)` | `canvas.add_event_listener("click", clicked)` with `def clicked(e):` |
|
|
129
|
+
| `const w = ctx.measureText("Hi").width` | `w = await ctx.measure_text("Hi").width` |
|
|
130
|
+
| `Math.PI` | `math.pi` |
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
// JavaScript
|
|
134
|
+
const cube = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1),
|
|
135
|
+
new THREE.MeshStandardMaterial({ color: 0x44aaff }));
|
|
136
|
+
scene.add(cube);
|
|
137
|
+
function animate() {
|
|
138
|
+
cube.rotation.y += 0.01;
|
|
139
|
+
renderer.render(scene, camera);
|
|
140
|
+
requestAnimationFrame(animate);
|
|
141
|
+
}
|
|
142
|
+
animate();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
# Python
|
|
147
|
+
cube = THREE.Mesh(THREE.BoxGeometry(1, 1, 1),
|
|
148
|
+
THREE.MeshStandardMaterial(color=0x44aaff))
|
|
149
|
+
scene.add(cube)
|
|
150
|
+
|
|
151
|
+
def draw():
|
|
152
|
+
cube.rotation.y += 0.01
|
|
153
|
+
renderer.render(scene, camera)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The full guide, with a 2D and a 3D example side by side: [Bringing a JavaScript example across](docs/from-javascript.md).
|
|
157
|
+
|
|
158
|
+
## Examples
|
|
159
|
+
|
|
160
|
+
In [`examples/`](examples), each with a comment at the top saying what it shows:
|
|
161
|
+
|
|
162
|
+
| File | What it is |
|
|
163
|
+
|---|---|
|
|
164
|
+
| `star_catcher.py` | A 2D game with sprites, a score and lives |
|
|
165
|
+
| `cube_dodge.py` | A 3D game: dodge the oncoming blocks |
|
|
166
|
+
| `lit_scene.py` | Shapes on a floor with a spotlight and shadows |
|
|
167
|
+
| `bouncing_balls.py` | A 2D animation with trails; click to add balls |
|
|
168
|
+
| `solar_system.py` | Planets, a moon and 2,000 stars in 3D |
|
|
169
|
+
| `live_chart.py` | A live line chart with a readout under the mouse |
|
|
170
|
+
| `type_and_measure.py` | Keyboard input, and reading a value back with `await` |
|
|
171
|
+
| `from_javascript_2d.py`, `from_javascript_3d.py` | JavaScript examples brought across |
|
|
172
|
+
| `website/` | A web page with two scenes on it |
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
pyctures run examples/star_catcher.py
|
|
176
|
+
pyctures run examples # a list of them all
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Docs
|
|
180
|
+
|
|
181
|
+
Start with [Getting started](docs/getting-started.md), then [how a program is shaped](docs/program-shape.md), [drawing in 2D](docs/drawing-2d.md), [3D scenes](docs/3d.md), [colours](docs/colours.md), and [tips](docs/tips.md). The [2D functions](docs/2d-functions.md) and [3D functions](docs/3d-functions.md) pages list everything, one line each. Seven tutorials are in [docs/tutorials](docs/tutorials).
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
## Pyctures in Circuitry Studio
|
|
185
|
+
|
|
186
|
+
Pyctures comes from [Circuitry Studio](https://www.circuitry.dev), where Python scenes run in a code editor with a live preview beside the code, with a debugger and ready-made examples. It runs on phones, iPad, the web and desktop, and no subscription is needed to use it. Scenes written with this library run there unchanged, and the other way round.
|
|
187
|
+
|
|
188
|
+

|
|
189
|
+
|
|
190
|
+
Its help pages: [Pyctures help](https://www.circuitry.dev/docs/pyctures) · [2D functions](https://www.circuitry.dev/docs/pyctures/2d-functions) · [3D functions](https://www.circuitry.dev/docs/pyctures/3d-functions) · [Colours](https://www.circuitry.dev/docs/pyctures/colours) · [Bringing a JavaScript example across](https://www.circuitry.dev/docs/pyctures/from-javascript)
|
|
191
|
+
|
|
192
|
+
## Licence
|
|
193
|
+
|
|
194
|
+
MIT. See [LICENSE](LICENSE). Pyctures includes three.js (MIT) and loads Pyodide (MPL 2.0) from its CDN; see [THIRD-PARTY-NOTICES](THIRD-PARTY-NOTICES).
|
|
195
|
+
|
|
196
|
+
Author: John Wylie
|
pyctures-0.1.0/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Pyctures
|
|
2
|
+
|
|
3
|
+
Pyctures ("Python pictures") gives Python the full set of JavaScript graphics functions: the web's 2D canvas for 2D, and three.js for 3D. Write a short Python program and it draws in your web browser: shapes, text, moving sprites, games, animations, live charts and lit 3D scenes. The names are the ones JavaScript uses, so any JavaScript graphics example can be brought across easily. Run a scene with your own Python while you write it, then build it into a folder that runs in any browser, on any website.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install pyctures
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Python 3.9 or newer. Nothing else is installed.
|
|
14
|
+
|
|
15
|
+
## A first scene
|
|
16
|
+
|
|
17
|
+
Save this as `hello.py`:
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import math
|
|
21
|
+
|
|
22
|
+
def draw():
|
|
23
|
+
ctx.fill_style = "midnightblue"
|
|
24
|
+
ctx.fill_rect(0, 0, width, height)
|
|
25
|
+
for i in range(12):
|
|
26
|
+
ctx.fill_style = f"hsl({i * 30}, 80%, 60%)"
|
|
27
|
+
ctx.begin_path()
|
|
28
|
+
ctx.arc(width / 2 + 120 * math.cos(i / 1.91), height / 2 + 120 * math.sin(i / 1.91), 20, 0, math.tau)
|
|
29
|
+
ctx.fill()
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`draw()` is called every frame, `ctx` is the 2D drawing surface, and `width` and `height` are the size of the canvas. There is nothing to import.
|
|
33
|
+
|
|
34
|
+
## Run it
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pyctures run hello.py
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Your browser opens on the scene. The program runs in your own Python, so numpy and anything else you have installed works. Save the file and the scene runs again. Errors are shown on the page with the line they happened on.
|
|
41
|
+
|
|
42
|
+
Options: `--port 9000`, `--no-browser`.
|
|
43
|
+
|
|
44
|
+
## Share it
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pyctures build hello.py -o site/
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`site/` is a folder of plain files that runs the scene entirely in the browser, with [Pyodide](https://pyodide.org) loaded from its official CDN. Put it on any static host. Every path in it is relative.
|
|
51
|
+
|
|
52
|
+
Or make one file:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pyctures build hello.py -o hello.html
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`hello.html` holds the scene and everything it needs (three.js too, if the scene is 3D), so you can email it, put it on any website, or open it straight from your disk. Python still loads from Pyodide's CDN.
|
|
59
|
+
|
|
60
|
+
Either way, images the scene loads by a relative path, such as `load_image("textures/brick.png")` or `THREE.TextureLoader().load("textures/brick.png")`, are included automatically: copied into the folder, or packed into the one file. A named image that is missing is reported as a warning.
|
|
61
|
+
|
|
62
|
+
Python runs in a background thread of the browser (a Web Worker), and the page only draws. A slow frame or a stuck loop cannot hold up the page, so scenes play smoothly on phones and tablets too. Add `?measure=1` to the address to see the frame rate and where each frame's time goes.
|
|
63
|
+
|
|
64
|
+
## Use it on your website
|
|
65
|
+
|
|
66
|
+
Either put a built scene in an iframe:
|
|
67
|
+
|
|
68
|
+
```html
|
|
69
|
+
<iframe src="hello/index.html" style="width: 100%; aspect-ratio: 16 / 9; border: 0"></iframe>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
or put scenes straight into your page, as many as you like:
|
|
73
|
+
|
|
74
|
+
```html
|
|
75
|
+
<div data-pyctures-src="balls.py"></div>
|
|
76
|
+
<div data-pyctures-src="knot.py" style="height: 420px"></div>
|
|
77
|
+
<script type="module" src="pyctures/pyctures.js"></script>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Each canvas fills its box, starts when it scrolls into view, and pauses when it is out of view or the tab is hidden. All the scenes on a page share one copy of Python, in a background thread. `pyctures build my-page/ -o site/` copies your page and adds the `pyctures/` folder. See [Use it on your website](docs/website.md), and the two-scene page in [`examples/website`](examples/website).
|
|
81
|
+
|
|
82
|
+
## Bringing a JavaScript example across
|
|
83
|
+
|
|
84
|
+
The calls are the same; a few things are written the Python way.
|
|
85
|
+
|
|
86
|
+
| JavaScript | Python |
|
|
87
|
+
|---|---|
|
|
88
|
+
| `new THREE.Mesh(g, m)` | `THREE.Mesh(g, m)` |
|
|
89
|
+
| `{ color: 0x44aaff, roughness: 0.4 }` | `color=0x44aaff, roughness=0.4` |
|
|
90
|
+
| `const x = 1;` `let y = 2;` | `x = 1` `y = 2` |
|
|
91
|
+
| `ctx.fillStyle = "red"` | the same, or `ctx.fill_style = "red"` |
|
|
92
|
+
| a `requestAnimationFrame` loop | `def draw():` and `def update(dt):` |
|
|
93
|
+
| `canvas.addEventListener("click", (e) => …)` | `canvas.add_event_listener("click", clicked)` with `def clicked(e):` |
|
|
94
|
+
| `const w = ctx.measureText("Hi").width` | `w = await ctx.measure_text("Hi").width` |
|
|
95
|
+
| `Math.PI` | `math.pi` |
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
// JavaScript
|
|
99
|
+
const cube = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1),
|
|
100
|
+
new THREE.MeshStandardMaterial({ color: 0x44aaff }));
|
|
101
|
+
scene.add(cube);
|
|
102
|
+
function animate() {
|
|
103
|
+
cube.rotation.y += 0.01;
|
|
104
|
+
renderer.render(scene, camera);
|
|
105
|
+
requestAnimationFrame(animate);
|
|
106
|
+
}
|
|
107
|
+
animate();
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
# Python
|
|
112
|
+
cube = THREE.Mesh(THREE.BoxGeometry(1, 1, 1),
|
|
113
|
+
THREE.MeshStandardMaterial(color=0x44aaff))
|
|
114
|
+
scene.add(cube)
|
|
115
|
+
|
|
116
|
+
def draw():
|
|
117
|
+
cube.rotation.y += 0.01
|
|
118
|
+
renderer.render(scene, camera)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The full guide, with a 2D and a 3D example side by side: [Bringing a JavaScript example across](docs/from-javascript.md).
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
In [`examples/`](examples), each with a comment at the top saying what it shows:
|
|
126
|
+
|
|
127
|
+
| File | What it is |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `star_catcher.py` | A 2D game with sprites, a score and lives |
|
|
130
|
+
| `cube_dodge.py` | A 3D game: dodge the oncoming blocks |
|
|
131
|
+
| `lit_scene.py` | Shapes on a floor with a spotlight and shadows |
|
|
132
|
+
| `bouncing_balls.py` | A 2D animation with trails; click to add balls |
|
|
133
|
+
| `solar_system.py` | Planets, a moon and 2,000 stars in 3D |
|
|
134
|
+
| `live_chart.py` | A live line chart with a readout under the mouse |
|
|
135
|
+
| `type_and_measure.py` | Keyboard input, and reading a value back with `await` |
|
|
136
|
+
| `from_javascript_2d.py`, `from_javascript_3d.py` | JavaScript examples brought across |
|
|
137
|
+
| `website/` | A web page with two scenes on it |
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pyctures run examples/star_catcher.py
|
|
141
|
+
pyctures run examples # a list of them all
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Docs
|
|
145
|
+
|
|
146
|
+
Start with [Getting started](docs/getting-started.md), then [how a program is shaped](docs/program-shape.md), [drawing in 2D](docs/drawing-2d.md), [3D scenes](docs/3d.md), [colours](docs/colours.md), and [tips](docs/tips.md). The [2D functions](docs/2d-functions.md) and [3D functions](docs/3d-functions.md) pages list everything, one line each. Seven tutorials are in [docs/tutorials](docs/tutorials).
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
## Pyctures in Circuitry Studio
|
|
150
|
+
|
|
151
|
+
Pyctures comes from [Circuitry Studio](https://www.circuitry.dev), where Python scenes run in a code editor with a live preview beside the code, with a debugger and ready-made examples. It runs on phones, iPad, the web and desktop, and no subscription is needed to use it. Scenes written with this library run there unchanged, and the other way round.
|
|
152
|
+
|
|
153
|
+

|
|
154
|
+
|
|
155
|
+
Its help pages: [Pyctures help](https://www.circuitry.dev/docs/pyctures) · [2D functions](https://www.circuitry.dev/docs/pyctures/2d-functions) · [3D functions](https://www.circuitry.dev/docs/pyctures/3d-functions) · [Colours](https://www.circuitry.dev/docs/pyctures/colours) · [Bringing a JavaScript example across](https://www.circuitry.dev/docs/pyctures/from-javascript)
|
|
156
|
+
|
|
157
|
+
## Licence
|
|
158
|
+
|
|
159
|
+
MIT. See [LICENSE](LICENSE). Pyctures includes three.js (MIT) and loads Pyodide (MPL 2.0) from its CDN; see [THIRD-PARTY-NOTICES](THIRD-PARTY-NOTICES).
|
|
160
|
+
|
|
161
|
+
Author: John Wylie
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
THIRD-PARTY NOTICES
|
|
2
|
+
|
|
3
|
+
Pyctures includes or loads the following third-party software.
|
|
4
|
+
|
|
5
|
+
--------------------------------------------------------------------------------
|
|
6
|
+
three.js (r179, version 0.179.1)
|
|
7
|
+
https://threejs.org - https://github.com/mrdoob/three.js
|
|
8
|
+
|
|
9
|
+
Included in this package as:
|
|
10
|
+
src/pyctures/web/three/three.module.min.js
|
|
11
|
+
src/pyctures/web/three/three.core.min.js
|
|
12
|
+
src/pyctures/web/three/OrbitControls.js
|
|
13
|
+
(from examples/jsm/controls/OrbitControls.js; its import of 'three' is
|
|
14
|
+
changed to the relative './three.module.min.js' so it loads without an
|
|
15
|
+
import map)
|
|
16
|
+
|
|
17
|
+
Licence: MIT
|
|
18
|
+
|
|
19
|
+
The MIT License
|
|
20
|
+
|
|
21
|
+
Copyright © 2010-2025 three.js authors
|
|
22
|
+
|
|
23
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
24
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
25
|
+
in the Software without restriction, including without limitation the rights
|
|
26
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
27
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
28
|
+
furnished to do so, subject to the following conditions:
|
|
29
|
+
|
|
30
|
+
The above copyright notice and this permission notice shall be included in
|
|
31
|
+
all copies or substantial portions of the Software.
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
36
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
37
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
38
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
39
|
+
THE SOFTWARE.
|
|
40
|
+
|
|
41
|
+
--------------------------------------------------------------------------------
|
|
42
|
+
Pyodide (version 0.29.4)
|
|
43
|
+
https://pyodide.org - https://github.com/pyodide/pyodide
|
|
44
|
+
|
|
45
|
+
NOT included in this package. Pages written by `pyctures build`, and pages
|
|
46
|
+
that use the browser half on their own, load Pyodide at run time from its
|
|
47
|
+
official CDN:
|
|
48
|
+
https://cdn.jsdelivr.net/pyodide/v0.29.4/full/
|
|
49
|
+
|
|
50
|
+
Licence: Mozilla Public License 2.0 (https://mozilla.org/MPL/2.0/).
|
|
51
|
+
Pyodide includes CPython (Python Software Foundation License) and the
|
|
52
|
+
packages it distributes each carry their own licence; see
|
|
53
|
+
https://pyodide.org/en/stable/project/about.html and the files on the CDN.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pyctures"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python 2D and 3D graphics, drawn in your web browser. Games, animations, charts and 3D scenes."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE", "THIRD-PARTY-NOTICES"]
|
|
13
|
+
authors = [{ name = "John Wylie" }]
|
|
14
|
+
keywords = ["graphics", "canvas", "3d", "three.js", "games", "animation", "education", "pyodide"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Education",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Games/Entertainment",
|
|
28
|
+
"Topic :: Multimedia :: Graphics",
|
|
29
|
+
"Topic :: Multimedia :: Graphics :: 3D Rendering",
|
|
30
|
+
"Topic :: Education",
|
|
31
|
+
]
|
|
32
|
+
dependencies = []
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
test = ["pytest>=7", "playwright>=1.40"]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/johnwylie70/pyctures"
|
|
39
|
+
Documentation = "https://github.com/johnwylie70/pyctures/tree/main/docs"
|
|
40
|
+
Source = "https://github.com/johnwylie70/pyctures"
|
|
41
|
+
Issues = "https://github.com/johnwylie70/pyctures/issues"
|
|
42
|
+
|
|
43
|
+
[project.scripts]
|
|
44
|
+
pyctures = "pyctures.cli:main"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools]
|
|
47
|
+
package-dir = { "" = "src" }
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.packages.find]
|
|
50
|
+
where = ["src"]
|
|
51
|
+
|
|
52
|
+
[tool.setuptools.package-data]
|
|
53
|
+
pyctures = ["web/*.js", "web/three/*"]
|
|
54
|
+
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
testpaths = ["tests"]
|
pyctures-0.1.0/setup.cfg
ADDED