Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Adding support for py5-web #318

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6c75798
(WIP) Adding support for py5-web
taconi Jan 2, 2025
95a918e
Merge branch 'main' into 317-py5
taconi Jan 3, 2025
d5df23b
Adjusting compatibility with py5
taconi Jan 3, 2025
0a096b4
Increasing compatibility with the py5 api
taconi Jan 3, 2025
37959fc
Increasing compatibility with the py5 api
taconi Jan 4, 2025
13f348d
Merge branch 'main' into 317-py5
taconi Jan 5, 2025
39a3672
Update pyodide
taconi Jan 6, 2025
4092790
Fixing py5 random functions
taconi Jan 6, 2025
026dd8e
Fixing Vertex Based Shapes Functions
taconi Jan 6, 2025
7ff76c3
Creating set_println_stream function
taconi Jan 6, 2025
af1adad
Merge branch 'main' into 317-py5
taconi Jan 6, 2025
21ea669
Merge branch 'main' into 317-py5
taconi Jan 7, 2025
65ed5ed
Adding py5 copyright
taconi Jan 7, 2025
4c33543
Fix py5.println
taconi Jan 7, 2025
110bd9a
Key event support
taconi Jan 7, 2025
02f31e0
Implementing Py5Vector based on py5 code
taconi Jan 7, 2025
00a6ec9
Implementing Py5MouseEvent based on py5 code
taconi Jan 8, 2025
a936966
Merge branch 'main' into 317-py5
taconi Jan 10, 2025
f8b71ab
Merge branch 'main' into 317-py5
taconi Jan 13, 2025
fa096c0
Removing non-py5 functions
taconi Jan 20, 2025
4e2128d
Set stderr
taconi Jan 20, 2025
9fa7738
fix build
taconi Jan 20, 2025
e89faff
Adjusting py5 panicCodes
taconi Jan 25, 2025
56eddd3
Adjustment in comparison of *args
taconi Jan 26, 2025
40880d8
Remap error adjustment
taconi Jan 26, 2025
d8f5180
Removing try/except to handle events to avoid omitting errors in call…
taconi Jan 26, 2025
a55560e
Merge branch 'main' into 317-py5
taconi Jan 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

<body class="min-h-screen font-sans antialiased overscroll-none overflow-hidden text-slate-50">
<div id="root"></div>
<script src="https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to have this installed as an npm package instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had installed pyodide with npm but I had the same error as this issue reports and the solution was to install via cdn.

Maybe updating the node or some other dependency will solve the problem, I'll test this later.

If it doesn't work, would installing pyodide via cdn block the merge?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see!

If it doesn't work, would installing pyodide via cdn block the merge?

No, I wouldn't go as far as that. It's just that I try to avoid depending on CDN for external code so that Flok also works offline, as an installable package (e.g. for LAN jams). But if we get stuck, we could go ahead and leave that for another future issue/PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with the latest version of node.js currently (23.5.0) and the error persists. Maybe we could remove the cdn from index.html and set it to be loaded only when the session is py5, I believe that this way the other targets would continue to work.
I'm not familiar with react (front-end in general) but I'll see how to load via cdn within the py5 wrapper with react

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not needed because flok already has p5 installed as package dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the installation of pyodide via the CDN, the p5 installed with npm was not found by pyodide, after the installation with the CDN it worked.

I believe that by solving the pyodide problem this will be resolved.

(I didn't test the p5 to see if there was an error due to yet another installation using the CDN, the idea is to remove the CDN, but I'll test it so I can already map it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick test and the p5 in the hydra sessions continues to work without any apparent conflicts

<script type="module" src="/src/main.tsx"></script>
</body>

Expand Down
31 changes: 31 additions & 0 deletions packages/web/src/components/py5-canvas.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { cn } from "@/lib/utils";
import { DisplaySettings } from "@/lib/display-settings";

interface Py5CanvasProps {
fullscreen?: boolean;
displaySettings: DisplaySettings;
ref: React.RefObject<HTMLCanvasElement>;
}

const Py5Canvas = ({
fullscreen,
displaySettings,
ref,
}: Py5CanvasProps) => (
<canvas
ref={ref}
className={cn(
"absolute top-0 left-0",
fullscreen && "h-full w-full block overflow-hidden"
)}
style={{
imageRendering: "pixelated",
display: displaySettings.showCanvas ? "" : "none",
}}
width={window.innerWidth / displaySettings.canvasPixelSize}
height={window.innerHeight / displaySettings.canvasPixelSize}
/>
);

export default React.memo(Py5Canvas);
Loading
Loading