fixed and sorted/added comments to L-System
This commit is contained in:
43
loader.html
43
loader.html
@@ -4,21 +4,37 @@
|
||||
<script src="js/p5.js"></script>
|
||||
</head>
|
||||
<body style="background-color: beige; margin: 0;">
|
||||
<script id="sketch"></script>
|
||||
<div id="error" style="color: red; padding: 20px; display: none;"></div>
|
||||
<script>
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
let sketchName = "sketches/" + params.get('sketch');
|
||||
if (sketchName == "sketches/") {
|
||||
sketchName = "sketches/" + params.get('sketches');
|
||||
let sketchName = params.get('sketch');
|
||||
if (!sketchName) {
|
||||
sketchName = params.get('sketches');
|
||||
}
|
||||
|
||||
if (sketchName) {
|
||||
console.log(sketchName+" found");
|
||||
if (!sketchName.endsWith('.js')) {
|
||||
sketchName += '.js';
|
||||
}
|
||||
|
||||
const script = document.getElementById('sketch');
|
||||
script.src = sketchName;
|
||||
|
||||
const sketchPath = 'sketches/' + sketchName;
|
||||
console.log('Loading sketch:', sketchPath);
|
||||
|
||||
// Load the sketch directly
|
||||
const script = document.createElement('script');
|
||||
script.src = sketchPath;
|
||||
script.onload = () => {
|
||||
console.log('Sketch loaded successfully');
|
||||
};
|
||||
script.onerror = () => {
|
||||
console.error('Failed to load sketch:', sketchPath);
|
||||
document.getElementById('error').style.display = 'block';
|
||||
document.getElementById('error').textContent = `Error loading sketch: ${sketchName}`;
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
} else {
|
||||
document.getElementById('error').style.display = 'block';
|
||||
document.getElementById('error').textContent = 'No sketch specified. Use ?sketch=filename.js';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
@@ -27,5 +43,16 @@
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
#error {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background: white;
|
||||
border: 2px solid red;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
max-width: 400px;
|
||||
}
|
||||
</style>
|
||||
</html>
|
||||
Reference in New Issue
Block a user