-
-
Notifications
You must be signed in to change notification settings - Fork 51
WIP: Adding support for py5-web #318
base: main
Are you sure you want to change the base?
Conversation
packages/web/index.html
Outdated
|
|
||
| <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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
packages/web/index.html
Outdated
| <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> | ||
| <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
Description
Inspired by @berinhard's pyp5js more specifically @villares' fork, the idea is to use the python syntax with pyodide to access p5js.
related #317
If anyone wants to play/test, I created a flok server with py5-web.
I will upload the PR updates and adjustments on this server
Todo list
Maintain the py5 API
Py5 Reference
Drawing Shapes
Basic Elements
arc()circle()ellipse()ellipse_mode()line()lines()point()points()quad()rect()rect_mode()square()triangle()3D Shapes
box()sphere()sphere_detail()Vertex Based Shapes
begin_closed_shape()begin_contour()begin_shape()bezier_vertex()bezier_vertices()curve_vertex()curve_vertices()end_contour()end_shape()quadratic_vertex()quadratic_vertices()vertex()vertices()Standalone Curves
bezier()bezier_detail()bezier_point()bezier_tangent()curve()curve_detail()curve_point()curve_tangent()curve_tightness()Creating and Displaying Shape Objects
create_shape()load_shape()convert_shape()convert_cached_shape()shape()shape_mode()Color and Other Graphic Attributes
Creating and Setting Colors
background()clear()color_mode()fill()no_fill()no_stroke()stroke()color()lerp_color()Analyzing Colors
hex_color()alpha()blue()brightness()green()hue()red()saturation()Stroke Attributes and Style Control
stroke_weight()stroke_cap()stroke_join()pop_style()push_style()push()pop()Inputs
Reading Files
load_bytes()load_json()load_pickle()load_strings()parse_json()select_folder()select_input()Keyboard Variables
is_key_pressedkeykey_codeKeyboard Event Functions
key_pressed()key_released()key_typed()Mouse Variables
is_mouse_pressedmouse_buttonmouse_xmouse_ypmouse_xpmouse_yrmouse_xrmouse_yMouse Event Functions
mouse_pressed()mouse_released()mouse_clicked()mouse_dragged()mouse_wheel()mouse_moved()mouse_entered()mouse_exited()Time & Date Helpers
day()hour()millis()minute()month()second()year()Output
Saving Files
begin_raw()begin_record()end_raw()end_record()save_bytes()save_json()save_pickle()save_strings()select_output()Image Output
save()save_frame()Text Area (Console)
println()set_println_stream()Typography
Drawing Text
text()text_align()text_leading()text_mode()text_size()Loading & Selecting Fonts
create_font()load_font()text_font()Text Metrics
text_width()text_ascent()text_descent()Coordinate System Transformations
Basic Operations
push_matrix()pop_matrix()translate()rotate()scale()shear_x()shear_y()3D Rotations
rotate_x()rotate_y()rotate_z()Matrix Operations
apply_matrix()get_matrix()print_matrix()reset_matrix()set_matrix()Sketch Environment
Setup and Variables
size()full_screen()widthheightsmooth()no_smooth()cursor()no_cursor()frame_countframe_rate()get_frame_rate()display_density()pixel_density()display_heightdisplay_widthfocusedsketch_path()Other Window Controls
get_surface()pixel_heightpixel_widthratio_leftratio_scaleratio_toprheightrwidthwindow_move()window_ratio()window_resizable()window_resize()window_title()window_xwindow_yMath Related
Calculation
ceil()constrain()dist()exp()floor()lerp()log()mag()norm()remap()sq()sqrt()Random
noise()noise_detail()noise_seed()np_randomos_noise()os_noise_seed()random()random_choice()random_gaussian()random_int()random_sample()random_seed()Trigonometry
acos()asin()atan()atan2()cos()degrees()radians()sin()tan()Working with Images
Loading and Displaying
image()image_mode()load_image()no_tint()tint()Pixels
apply_filter()blend()copy()get_np_pixels()get_pixels()load_np_pixels()load_pixels()np_pixels[]pixels[]set_np_pixels()set_pixels()to_pil()update_np_pixels()update_pixels()Textures
texture()texture_mode()texture_wrap()Image Objects
create_image()convert_image()convert_cached_image()create_image_from_numpy()request_image()3D Scene
Camera
begin_camera()camera()end_camera()frustum()ortho()perspective()print_camera()print_projection()Coordinates
model_x()model_y()model_z()screen_x()screen_y()screen_z()Lights
ambient_light()directional_light()light_falloff()light_specular()lights()no_lights()normal()point_light()spot_light()Material Properties
ambient()emissive()shininess()specular()Rendering
Graphics Context
blend_mode()clip()create_graphics()flush()get_graphics()hint()no_clip()Shaders
load_shader()reset_shader()shader()Sketch Execution
Draw Loop Control
loop()no_loop()redraw()exit_sketch()exiting()Advanced Execution Control
finishedhot_reload_draw()is_deadis_dead_from_erroris_readyis_runningpargsPerformance Profiling
print_line_profiler_stats()profile_draw()profile_functions()Threading
has_thread()join_thread()launch_promise_thread()launch_repeating_thread()launch_thread()list_threads()stop_all_threads()stop_thread()JVM Constants
java_platformjava_version_namePy5 Functions
@render()@render_sequence()create_font_file()get_current_sketch()prune_tracebacks()register_image_conversion()register_shape_conversion()render_frame()render_frame_sequence()reset_py5()set_stackprinter_style()Classes
Py5GraphicsPy5ImagePy5ShapePy5ShaderPy5SurfacePy5FontPy5MouseEventPy5KeyEventPy5VectorEvents
Init
settings()setup()draw()Window
window_moved()window_resized()Movie
movie_event()Update
predraw_update()draw().Camera3D Support
These functions are only for Sketches that use the Processing library Camera3D with py5; without Camera3D, py5 will never call them.
pre_draw()draw()post_draw()draw()