tidy examples
This commit is contained in:
parent
eb68dec2ad
commit
70b8d7c143
12 changed files with 120 additions and 6 deletions
|
@ -1 +0,0 @@
|
||||||
pyglm
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# python3 -m pip install pyglm
|
||||||
|
|
||||||
from math import sin, cos
|
from math import sin, cos
|
||||||
import glm
|
import glm
|
||||||
from raylib import rl, ffi
|
from raylib import rl, ffi
|
|
@ -2,7 +2,7 @@
|
||||||
RenderTexture example
|
RenderTexture example
|
||||||
|
|
||||||
Run with:
|
Run with:
|
||||||
|
python3 -m pip install pyglm
|
||||||
python3 flow-field
|
python3 flow-field
|
||||||
flow-field bees
|
flow-field bees
|
||||||
"""
|
"""
|
|
@ -1 +0,0 @@
|
||||||
pyglm
|
|
|
@ -78,7 +78,7 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
||||||
angle -= 0.002
|
angle -= 0.002
|
||||||
camera.position.x = math.sin(angle) * 30.0
|
camera.position.x = math.sin(angle) * 30.0
|
||||||
camera.position.z = math.cos(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.x = rl.GetMouseX()
|
||||||
swirl.y = screenHeight - rl.GetMouseY()
|
swirl.y = screenHeight - rl.GetMouseY()
|
||||||
|
|
|
@ -61,7 +61,7 @@ while not rl.WindowShouldClose():
|
||||||
a += 0.01
|
a += 0.01
|
||||||
camera.position.x = math.sin(a) * 6
|
camera.position.x = math.sin(a) * 6
|
||||||
camera.position.z = math.cos(a) * 6
|
camera.position.z = math.cos(a) * 6
|
||||||
rl.UpdateCamera(camera)
|
rl.UpdateCamera(camera, rl.CAMERA_PERSPECTIVE)
|
||||||
|
|
||||||
lightSystem.update(camera.position)
|
lightSystem.update(camera.position)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ raylib [texture] example - To image
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from pyray import *
|
from pyray import *
|
||||||
from raylib.colors import *
|
|
||||||
|
|
||||||
# Initialization
|
# Initialization
|
||||||
screenWidth = 800
|
screenWidth = 800
|
||||||
|
|
115
web_examples.py
Normal file
115
web_examples.py
Normal file
|
@ -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("<html>\n<head>\n<title>Directory Index</title>\n</head>\n<body>\n")
|
||||||
|
|
||||||
|
# Write the title of the page
|
||||||
|
index_file.write("<h1>Directory Index</h1>\n")
|
||||||
|
|
||||||
|
# Write the list of subdirectories
|
||||||
|
index_file.write("<ul>\n")
|
||||||
|
sub_dirs = os.listdir(output_dir)
|
||||||
|
|
||||||
|
# Sort the list of subdirectories in alphabetical order
|
||||||
|
sub_dirs.sort()
|
||||||
|
|
||||||
|
# Loop through the sorted subdirectories
|
||||||
|
for sub_dir in sub_dirs:
|
||||||
|
|
||||||
|
# Check if the subdirectory is a directory
|
||||||
|
if os.path.isdir(os.path.join(output_dir, sub_dir)):
|
||||||
|
|
||||||
|
# Write the subdirectory name and the link to frank.html
|
||||||
|
index_file.write(f"<li><a href='{sub_dir}/build/web'>{sub_dir}</a>")
|
||||||
|
#- <a href='{sub_dir}/main.py'>code</a></li>\n")
|
||||||
|
|
||||||
|
# Close the list tag
|
||||||
|
index_file.write("</ul>\n")
|
||||||
|
|
||||||
|
# Write the HTML footer
|
||||||
|
index_file.write("</body>\n</html>\n")
|
Reference in a new issue