diff --git a/examples/extra/camera.py.requirements.txt b/examples/extra/camera.py.requirements.txt deleted file mode 100644 index 0513c36..0000000 --- a/examples/extra/camera.py.requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pyglm \ No newline at end of file diff --git a/examples/extra/camera.py b/examples/extra/extra_camera.py similarity index 99% rename from examples/extra/camera.py rename to examples/extra/extra_camera.py index 9371dd4..c02a821 100644 --- a/examples/extra/camera.py +++ b/examples/extra/extra_camera.py @@ -1,3 +1,5 @@ +# python3 -m pip install pyglm + from math import sin, cos import glm from raylib import rl, ffi diff --git a/examples/extra/flow-field.py b/examples/extra/extra_flow_field.py similarity index 99% rename from examples/extra/flow-field.py rename to examples/extra/extra_flow_field.py index ae54e29..b9ef93e 100644 --- a/examples/extra/flow-field.py +++ b/examples/extra/extra_flow_field.py @@ -2,7 +2,7 @@ RenderTexture example Run with: - +python3 -m pip install pyglm python3 flow-field flow-field bees """ diff --git a/examples/extra/transparent_undecorated_window.py b/examples/extra/extra_transparent_undecorated_window.py similarity index 100% rename from examples/extra/transparent_undecorated_window.py rename to examples/extra/extra_transparent_undecorated_window.py diff --git a/examples/extra/flow-field.py.requirements.txt b/examples/extra/flow-field.py.requirements.txt deleted file mode 100644 index 0513c36..0000000 --- a/examples/extra/flow-field.py.requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pyglm \ No newline at end of file diff --git a/examples/physics/demo.py b/examples/physics/physac.py similarity index 100% rename from examples/physics/demo.py rename to examples/physics/physac.py diff --git a/examples/shaders/shaders_custom_uniform.py b/examples/shaders/shaders_custom_uniform.py index 9173752..cf90cd9 100755 --- a/examples/shaders/shaders_custom_uniform.py +++ b/examples/shaders/shaders_custom_uniform.py @@ -78,7 +78,7 @@ while not rl.WindowShouldClose(): #// Detect window close button or E angle -= 0.002 camera.position.x = math.sin(angle) * 30.0 camera.position.z = math.cos(angle) * 30.0 - rl.UpdateCamera(camera) #// Update camera + rl.UpdateCamera(camera, rl.CAMERA_PERSPECTIVE) #// Update camera swirl.x = rl.GetMouseX() swirl.y = screenHeight - rl.GetMouseY() diff --git a/examples/shaders/shaders_fog.py b/examples/shaders/shaders_fog.py index cb75075..34ff1c1 100755 --- a/examples/shaders/shaders_fog.py +++ b/examples/shaders/shaders_fog.py @@ -61,7 +61,7 @@ while not rl.WindowShouldClose(): a += 0.01 camera.position.x = math.sin(a) * 6 camera.position.z = math.cos(a) * 6 - rl.UpdateCamera(camera) + rl.UpdateCamera(camera, rl.CAMERA_PERSPECTIVE) lightSystem.update(camera.position) diff --git a/examples/textures/image_loading.py b/examples/textures/textures_image_loading.py similarity index 100% rename from examples/textures/image_loading.py rename to examples/textures/textures_image_loading.py diff --git a/examples/textures/opencv.py b/examples/textures/textures_opencv.py similarity index 100% rename from examples/textures/opencv.py rename to examples/textures/textures_opencv.py diff --git a/examples/textures/textures_to_image.py b/examples/textures/textures_to_image.py index 96c50a4..9b713a7 100644 --- a/examples/textures/textures_to_image.py +++ b/examples/textures/textures_to_image.py @@ -4,7 +4,6 @@ raylib [texture] example - To image """ from pyray import * -from raylib.colors import * # Initialization screenWidth = 800 diff --git a/web_examples.py b/web_examples.py new file mode 100644 index 0000000..f99713f --- /dev/null +++ b/web_examples.py @@ -0,0 +1,115 @@ +# Written by AI + +import os +import shutil + +def convert(file_name): + with open(file_name, "r") as f: + # Read the lines of the file + lines = f.readlines() + + # Create a temporary file name + temp_file_name = file_name + ".tmp" + + # Open the temporary file in write mode + with open(temp_file_name, "w") as f: + # Write the first line to define the main() function + f.write("""# /// script +# dependencies = [ +# "cffi", +# "inflection", +# "raylib" +# ] +# /// +import asyncio +import platform +from raylib import * +from pyray import * +async def main(): +""") + # Indent each line of the original file and write it to the temporary file + for line in lines: + if "from raylib import *" in line or "from pyray import *" in line: + pass + else: + f.write(" " + line) + + indent = line[:len(line) - len(line.lstrip())] + if "init_window" in line or "InitWindow" in line: + f.write(indent + " platform.window.window_resize()\n") + if "end_drawing" in line or "EndDrawing" in line: + f.write(indent + " await asyncio.sleep(0)\n") + + + + + # Write the last line to call the main() function + f.write("\nasyncio.run(main())\n") + + # Delete the original file + os.remove(file_name) + + # Rename the temporary file to the original file name + os.rename(temp_file_name, file_name) + +# Define the directory to start from +start_dir = "examples" + +# Define the output directory +output_dir = "webexamples" +os.mkdir(output_dir) + +# Loop through all the files and subdirectories +for root, dirs, files in os.walk(start_dir): + # Loop through the files that match the pattern '*.py' + for file in files: + if ((file.startswith("core") or file.startswith("phys") or file.startswith("shapes") or file.startswith("text")) + and file.endswith(".py")): + # Get the full path of the file + file_path = os.path.join(root, file) + # Get the file name without the extension + file_name = os.path.splitext(file)[0] + # Create a new directory with the same name as the file in the output directory + new_dir = os.path.join(output_dir, file_name) + os.mkdir(new_dir) + # Copy the file into the new directory and rename it 'main.py' + new_file = os.path.join(new_dir, "main.py") + shutil.copy(file_path, new_file) + convert(new_file) + os.system(f"cp -R examples/textures/resources {new_dir}") + os.system("python3.12 -m pygbag --git --PYBUILD 3.12 --no_opt --can_close 1 --ume_block 0 --template noctx.tmpl --build "+new_file) + os.system(f"rm -rf {new_dir}/resources") + +os.system(f"touch {output_dir}/.nojekyll") + +# Open the index.html file in write mode +with open(output_dir+"/index.html", "w") as index_file: + + # Write the HTML header + index_file.write("\n
\n