You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: run blocking pygame loops and render plots for the console
pygame:
- Ordinary blocking game loops now use SDL mode: with JSPI, the calls a
game loop makes (display.flip/update, Clock.tick, time.wait/delay,
event.wait) pause via run_sync so the browser can draw and Acode stays
responsive (python/acode_pygame.py)
- Check JSPI inside a task before running a blocking loop; without it,
fall back with an explanation instead of freezing Acode
- Stop blocking loops through a flag checked at those pauses, since
they never reach an await; stopped runs no longer print into the next
console
- Explain the worker's "dummy not available" error
Images:
- Default matplotlib figure size to the console width (via the
matplotlibrc read on first import), so text stays readable on phones
- Render at the device pixel ratio and display at true size, so plots
are sharp on HiDPI screens
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`matplotlib` figures are shown in the console when you call `plt.show()`, and any figures left open are shown when the program ends. Pillow's `Image.show()` works too.
32
+
`matplotlib` figures are shown in the console when you call `plt.show()`, and any figures left open are shown when the program ends. Figures default to the width of the console and are rendered at the screen's pixel density. Pillow's `Image.show()` works too.
33
33
34
34
### pygame (experimental)
35
35
36
-
pygame programs can draw to a canvas in the console using Pyodide's [SDL support](https://pyodide.org/en/stable/usage/sdl.html). The game loop must be async so the app stays responsive:
36
+
pygame programs can draw to a canvas in the console using Pyodide's [SDL support](https://pyodide.org/en/stable/usage/sdl.html). Ordinary game loops work as written:
37
37
38
38
```python
39
-
import asyncio
40
39
import pygame
41
40
42
41
pygame.init()
43
-
screen = pygame.display.set_mode((320, 240))
42
+
screen = pygame.display.set_mode((1280, 720))
43
+
clock = pygame.time.Clock()
44
44
45
-
asyncdefmain():
46
-
whileTrue:
47
-
screen.fill((30, 30, 60))
48
-
pygame.display.flip()
49
-
await asyncio.sleep(1/60)
50
-
51
-
await main()
45
+
whileTrue:
46
+
screen.fill("purple")
47
+
pygame.display.flip()
48
+
clock.tick(60)
52
49
```
53
50
54
-
If SDL cannot start, the program runs without a display. Running again or closing the console stops the game.
51
+
This needs a WebView with JSPI support (Android System WebView 137+), which lets the loop pause at `display.flip()` / `Clock.tick()` so the app stays responsive. On older WebViews, use an async loop (`await asyncio.sleep(0)` each frame) instead. If SDL cannot start, the program runs without a display. Running again or closing the console stops the game.
Copy file name to clipboardExpand all lines: changelog.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,8 @@
8
8
- Console output can now be selected and copied
9
9
- Header button to toggle line wrap in the console (remembered between sessions)
10
10
- Thin progress line under the console header while Python loads or code is running
11
-
- matplotlib plots are shown in the console (`plt.show()`, or automatically at the end of a run), as are Pillow `Image.show()` images
12
-
- Experimental SDL support: pygame programs with an async game loop draw to a canvas in the console, falling back to running without a display if SDL cannot start
11
+
- matplotlib plots are shown in the console (`plt.show()`, or automatically at the end of a run), as are Pillow `Image.show()` images. Plots are sized to the console and rendered sharp on high-density screens
12
+
- Experimental SDL support: pygame programs draw to a canvas in the console, including ordinary blocking game loops on WebViews with JSPI. Falls back to running without a display if SDL cannot start
13
13
- Python crashes no longer leave the console stuck; Python restarts on the next run
14
14
- Fixed Python failing to load (or staying on "loading...") on some devices
15
15
- Clear error message when Python fails to load, with automatic retry on the next run
0 commit comments